영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)
시간 제한 1초 · 메모리 제한 512 MB
Problem
There will be a chess tournament of n players. Each player has announced the number of games they want to play.
Each pair of players can play at most one game. Your task is to determine which games will be played so that everybody will be happy.
Input
The first input line has an integer n: the number of players. The players are numbered 1,2,…,n.
The next line has n integers x_1,x_2,…,x_n: for each player, the number of games they want to play.
Output
First print an integer k: the number of games. Then, print k lines describing the games. You can print any valid solution.
If there are no solutions, print "IMPOSSIBLE".
Constraints
- 1 ≤ n ≤ 10^5
- ∑_{i=1}^n x_i ≤ 2 · 10^5
예제
예제 1
5 1 3 2 0 2
4 1 2 2 3 2 5 3 5