#GD0000168. Phá hủy dãy số (Array Destruction)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phá hủy dãy số (Array Destruction)
Array Destruction
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You have a multiset of positive integers. Choose an initial positive sum . Repeat times: remove two occurrences whose sum equals the current , then replace with the larger removed value. Determine whether all elements can be removed, and output the initial sum and the ordered pairs if possible.
Input
The first line contains . The second contains exactly positive integers.
Output
Print NO if impossible. Otherwise print YES, the initial target sum, and then lines, each listing the two values removed at that step.
Subtasks
- Subtask 1 (20 points): ; for all .
- Subtask 2 (30 points): ; for all .
- Subtask 3 (50 points): ; for all .
Examples
Input
2
3 5 1 2
Output
YES
6
5 1
3 2
Explanation
Start with . Remove , whose sum is , then update to . Remove , whose sum is , leaving the multiset empty. Thus the construction is valid.