#GL0000070. Chuỗi đong nước tiết kiệm nhất (Water Containers Moves)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chuỗi đong nước tiết kiệm nhất (Water Containers Moves)
Water Containers Moves
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
Two containers A and B have capacities a and b and start empty. You may fill, empty, or pour between them until the source becomes empty or the destination becomes full. Every operation must actually move a positive amount of water. Find a sequence ending with exactly x units in A that minimizes the total amount of water moved, including filling and emptying. Output the number of operations and the total moved amount, followed by the operations FILL A, FILL B, EMPTY A, EMPTY B, MOVE A B, or MOVE B A. Print -1 if impossible.
Input
Three positive integers a b x.
Output
Either -1, or a first line containing n m followed by n valid operation lines, with minimum possible total moved amount m.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
5 3 4
Output
6 19
FILL A
MOVE A B
EMPTY B
MOVE A B
FILL A
MOVE A B
Explanation
The example moves lead to state (4,3) with moved amounts 5+3+3+2+5+1=19, which is minimal.