PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000102. Xếp các tòa tháp Phượng Hoàng (Phoenix and Towers)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Xếp các tòa tháp Phượng Hoàng (Phoenix and Towers)
Phoenix and Towers
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You have blocks of heights and must build nonempty towers using every block once. Tower height is the sum of its blocks. Assign every block so the difference between the tallest and shortest tower is at most . It is guaranteed that and . Print YES and tower indices if possible; otherwise NO.
Input
Line 1 contains . Line 2 contains integers .
Output
Print YES followed by tower indices in assigning each block, or NO if impossible. Any valid assignment is allowed.
Subtasks
- Subtask 1 (20 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (50 points): ; ; for every .
Examples
Input
4 2 3
1 2 3 1
Output
YES
1 2 1 2
Explanation
One valid assignment is for the four blocks: tower heights are and , with difference . Both towers are nonempty.