6966.Chess Tournament

Time Limit: 1s Memory Limit: 512MB

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 Format(From the terminal/stdin)

The first input line has an integer $n$ : the number of players. The players are numbered $1,2,\dots,n$ .

The next line has $n$ integers $x_1,x_2,\dots,x_n$ : for each player, the number of games they want to play.

  • $1 \le n \le 10^5$
  • $\sum_{i=1}^{n} x_i \le 2 \cdot 10^5$

Output Format(To the terminal/stdout)

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.

Sample Input

Copy
5
1 3 2 0 2
 \n
 · · · · \n

Sample Output special judge

Copy
4
1 2
2 3
2 5
3 5
 \n
 · \n
 · \n
 · \n
 · \n
Source: CSES, Construction Problems, 1697

Submit

请先 登录

© 2025 FAQs