luogu#P10056. Water

Water

Problem Description

There are nn cups. Each cup has capacity aa, and initially contains water of volume bb. You may perform any number of operations. In each operation, choose any two cups and pour all the water from one cup into the other cup, but during the process the water in the cup must not overflow (i.e., must not exceed its capacity). If this condition is not satisfied, then the operation cannot be performed.

Using legal operations, maximize the volume of water in the cup that contains the most water.

Input Format

One line with three integers a,b,na, b, n.

Output Format

One line with one integer xx, representing the volume of water in the cup that contains the most water.

5 2 2 
4
11 5 7 
10

Hint

Sample 1 Explanation

Suppose there are two cups A,BA, B. You can first pour all the water in AA into BB. Then AA has 00 liters of water and BB has 44 liters of water, and the operations end. At this time, the amount of water in the fullest cup is 44.

Constraints

Test Point ID nn \le Special Property
121 \sim 2 10510^5 It is guaranteed that no matter how you operate, overflow will never occur.
363 \sim 6 10610^6 None.
7107 \sim 10 10910^9

For 100%100\% of the testdata, 1n1091 \le n \le 10^9, 1a10181 \le a \le 10^{18}, and 1bmin(a,109)1 \le b \le \min(a, 10^9).

Translated by ChatGPT 5