#P1292. 倒酒
倒酒
Description
Winy is the owner of a bar. His bar offers two volumes of beer, ml and ml, served in cups with capacities ml and ml respectively.
Business is not good. Winy finds that the drunks are very poor. Sometimes they have to leave because they cannot afford ml or ml of beer. Therefore, Winy decides to sell a third volume of beer (a smaller volume).
Winy has only two cups with capacities ml and ml, and the cups have no markings. He can only obtain new volumes by pouring between the two cups and the barrel.
To simplify the pouring steps, Winy stipulates:
- .
- The barrel has infinite capacity, and the amount of beer in the barrel is also infinite (but much smaller than the barrel’s capacity).
- Only three pouring operations are allowed:
- Pour beer from the barrel into the cup of capacity ml.
- Pour the beer from the cup of capacity ml into the barrel.
- Pour the beer from the cup of capacity ml into the cup of capacity ml.
- Each pour must either fill the receiving cup to full or empty the source cup completely.
Winy hopes that after several pours, the remaining volume of beer in the ml cup is as small as possible. He asks you to help design a pouring plan.
Input Format
A single line with two integers and , satisfying .
Output Format
The first line contains an integer , representing the minimal volume that can be obtained.
The second line contains two integers and (separated by a space), representing respectively the number of times pouring from the ml cup into the barrel and the number of times pouring into the ml cup from the barrel.
If multiple pairs satisfy the requirement, output the one with the smallest . If there are still multiple choices under the smallest , output the one with the smallest .
5 3
1
1 2
Hint
Sample explanation:
The pouring plan is:
- Barrel -> cup B.
- Cup B -> cup A.
- Barrel -> cup B.
- Cup B -> cup A.
- Cup A -> barrel.
- Cup B -> cup A.
Translated by ChatGPT 5
京公网安备 11011102002149号