QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21162. Вёдра для молока

Statistics

Farmer John получил заказ ровно на $M$ единиц молока ($1 \leq M \leq 1,000$), который нужно выполнить немедленно. Но его дорогая доильная машина сломалась, и остались лишь три ведра целых объёмов $X$, $Y$ и $M$ ($1 \leq X < Y < M$). Все изначально пусты. Можно сколько угодно раз выполнять операции двух типов:

  • Наполнить наименьшее ведро объёма $X$ до краёв $X$ единицами молока и вылить в ведро объёма $M$, если ведро объёма $M$ не переполнится.
  • Наполнить среднее ведро объёма $Y$ до краёв $Y$ единицами молока и вылить в ведро объёма $M$, если ведро объёма $M$ не переполнится.

FJ понимает, что может не суметь наполнить ведро объёма $M$ полностью. Помогите найти максимум молока, который можно туда добавить.

Входные данные

Единственная строка содержит $X$, $Y$ и $M$ через пробел.

Выходные данные

Выведите максимум молока, который FJ может добавить в ведро объёма $M$.

Примеры

Входные данные 1

17 25 77

Выходные данные 1

76

Примечание

FJ наполняет ведро объёма 17 трижды, объёма 25 один раз, получая 76 единиц молока.

Автор: Brian Dean

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.