codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1579D.md (2217B)


      1 Source: https://codeforces.com/problemset/problem/1579/D
      2 
      3 D. Productive Meeting
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 An important meeting is to be held and there are exactly $n$ people invited. At any moment, any two people can step back and talk in private. The same two people can talk several (as many as they want) times per meeting.
     22 
     23 Each person has limited sociability. The sociability of the $i$-th person is a non-negative integer $a_i$. This means that after exactly $a_i$ talks this person leaves the meeting (and does not talk to anyone else anymore). If $a_i = 0$, the $i$-th person leaves the meeting immediately after it starts.
     24 
     25 A meeting is considered most productive if the maximum possible number of talks took place during it.
     26 
     27 You are given an array of sociability $a$, determine which people should talk to each other so that the total number of talks is as large as possible.
     28 
     29 Input
     30 
     31 The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of test cases.
     32 
     33 The next $2t$ lines contain descriptions of the test cases.
     34 
     35 The first line of each test case description contains an integer $n$ ($2 \le n \le 2 \cdot 10^5$) —the number of people in the meeting. The second line consists of $n$ space-separated integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$) — the sociability parameters of all people.
     36 
     37 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. It is also guaranteed that the sum of all $a_i$ (over all test cases and all $i$) does not exceed $2 \cdot 10^5$.
     38 
     39 Output
     40 
     41 Print $t$ answers to all test cases.
     42 
     43 On the first line of each answer print the number $k$ — the maximum number of talks possible in a meeting.
     44 
     45 On each of the next $k$ lines print two integers $i$ and $j$ ($1 \le i, j \le n$ and $i \neq j$) — the numbers of people who will have another talk.
     46 
     47 If there are several possible answers, you may print any of them.
     48 
     49 Example
     50 
     51 Input
     52 
     53 ```
     54 8
     55 2
     56 2 3
     57 3
     58 1 2 3
     59 4
     60 1 2 3 4
     61 3
     62 0 0 2
     63 2
     64 6 2
     65 3
     66 0 0 2
     67 5
     68 8 2 0 1 1
     69 5
     70 0 1 0 0 6
     71 ```
     72 
     73 Output
     74 
     75 ```
     76 2
     77 1 2
     78 1 2
     79 3
     80 1 3
     81 2 3
     82 2 3
     83 5
     84 1 3
     85 2 4
     86 2 4
     87 3 4
     88 3 4
     89 0
     90 2
     91 1 2
     92 1 2
     93 0
     94 4
     95 1 2
     96 1 5
     97 1 4
     98 1 2
     99 1
    100 5 2
    101 ```