#QHD0000011. Bài tập của Người Nhện (Spiderman's Workout)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bài tập của Người Nhện (Spiderman's Workout)
Spiderman's Workout
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Spiderman completes consecutive climbing stages. During stage , he must move vertically by exactly metres, either up (U) or down (D). The stages must be performed in their given order.
He starts at height and must finish at height , and his height must never become negative.
Among all legal routes, find a sequence of directions that minimizes the maximum height reached. If no legal route exists, print IMPOSSIBLE.
Input
The first line contains , the number of climbing stages.
The second line contains positive integers , the stage lengths in order.
Output
Print a string of exactly characters U or D describing an optimal legal route. Any optimal route is accepted. If no legal route exists, print IMPOSSIBLE.
Subtasks
- Subtask 1 (20 points): ; (); .
- Subtask 2 (30 points): ; (); .
- Subtask 3 (50 points): ; (); .
Examples
Input
4
20 20 20 20
Output
UDUD
Explanation
The route UDUD reaches heights . Its peak is ; any legal solution must climb in its first stage, so this peak is optimal.