codeforces-scrape

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

769B.md (2824B)


      1 Source: https://codeforces.com/problemset/problem/769/B
      2 
      3 B. News About Credit
      4 
      5 time limit per test
      6 
      7 1 second
      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 Polycarp studies at the university in the group which consists of *n* students (including himself). All they are registrated in the social net "TheContacnt!".
     22 
     23 Not all students are equally sociable. About each student you know the value *a**i* — the maximum number of messages which the *i*-th student is agree to send per day. The student can't send messages to himself.
     24 
     25 In early morning Polycarp knew important news that the programming credit will be tomorrow. For this reason it is necessary to urgently inform all groupmates about this news using private messages.
     26 
     27 Your task is to make a plan of using private messages, so that:
     28 
     29 * the student *i* sends no more than *a**i* messages (for all *i* from 1 to *n*);
     30 * all students knew the news about the credit (initially only Polycarp knew it);
     31 * the student can inform the other student only if he knows it himself.
     32 
     33 Let's consider that all students are numerated by distinct numbers from 1 to *n*, and Polycarp always has the number 1.
     34 
     35 In that task you shouldn't minimize the number of messages, the moment of time, when all knew about credit or some other parameters. Find any way how to use private messages which satisfies requirements above.
     36 
     37 Input
     38 
     39 The first line contains the positive integer *n* (2 ≤ *n* ≤ 100) — the number of students.
     40 
     41 The second line contains the sequence *a*1, *a*2, ..., *a**n* (0 ≤ *a**i* ≤ 100), where *a**i* equals to the maximum number of messages which can the *i*-th student agree to send. Consider that Polycarp always has the number 1.
     42 
     43 Output
     44 
     45 Print -1 to the first line if it is impossible to inform all students about credit.
     46 
     47 Otherwise, in the first line print the integer *k* — the number of messages which will be sent. In each of the next *k* lines print two distinct integers *f* and *t*, meaning that the student number *f* sent the message with news to the student number *t*. All messages should be printed in chronological order. It means that the student, who is sending the message, must already know this news. It is assumed that students can receive repeated messages with news of the credit.
     48 
     49 If there are several answers, it is acceptable to print any of them.
     50 
     51 Examples
     52 
     53 Input
     54 
     55 ```
     56 4  
     57 1 2 1 0
     58 ```
     59 
     60 Output
     61 
     62 ```
     63 3  
     64 1 2  
     65 2 4  
     66 2 3
     67 ```
     68 
     69 Input
     70 
     71 ```
     72 6  
     73 2 0 1 3 2 0
     74 ```
     75 
     76 Output
     77 
     78 ```
     79 6  
     80 1 3  
     81 3 4  
     82 1 2  
     83 4 5  
     84 5 6  
     85 4 6
     86 ```
     87 
     88 Input
     89 
     90 ```
     91 3  
     92 0 2 2
     93 ```
     94 
     95 Output
     96 
     97 ```
     98 -1
     99 ```
    100 
    101 Note
    102 
    103 In the first test Polycarp (the student number 1) can send the message to the student number 2, who after that can send the message to students number 3 and 4. Thus, all students knew about the credit.