#BS0000228. Ngăn ngập hồ (Avoid Flood in The City)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Ngăn ngập hồ (Avoid Flood in The City)
Avoid Flood in The City
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
There are lakes numbered from through , all initially empty. The array describes the weather for days.
On day , a positive fills lake ; rain on an already full lake causes a flood. When , no rain occurs and exactly one lake must be drained. Draining leaves the chosen lake empty even if it was already empty.
Find a drainage schedule that prevents every flood throughout the period. Any valid schedule is acceptable.
Input
The first line contains the integer . The second line contains integers in chronological order.
Output
If no schedule exists, print IMPOSSIBLE. Otherwise print integers on one line. Use on rainy days and on dry days to identify the lake drained.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
6
1 2 0 0 2 1
Output
-1 -1 2 1 -1 -1
Explanation
Days 1 and 2 fill lakes 1 and 2. Drain lake 2 on day 3 and lake 1 on day 4. Both are empty before their next rains on days 5 and 6. Reversing the two drainage choices also works.
Input
5
1 2 0 1 2
Output
IMPOSSIBLE
Explanation
Both lakes are full after day 2. The sole dry day, day 3, cannot empty both before their next rains.