codeforces-scrape

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

792B.md (1824B)


      1 Source: https://codeforces.com/problemset/problem/792/B
      2 
      3 B. Counting-out Rhyme
      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 *n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In the *i*-th step the leader counts out *a**i* people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader.
     22 
     23 For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and *a**i* = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader.
     24 
     25 You have to write a program which prints the number of the child to be eliminated on every step.
     26 
     27 Input
     28 
     29 The first line contains two integer numbers *n* and *k* (2 ≤ *n* ≤ 100, 1 ≤ *k* ≤ *n* - 1).
     30 
     31 The next line contains *k* integer numbers *a*1, *a*2, ..., *a**k* (1 ≤ *a**i* ≤ 109).
     32 
     33 Output
     34 
     35 Print *k* numbers, the *i*-th one corresponds to the number of child to be eliminated at the *i*-th step.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 7 5  
     43 10 4 11 4 1
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 4 2 5 6 1
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 3 2  
     56 2 5
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 3 2
     63 ```
     64 
     65 Note
     66 
     67 Let's consider first example:
     68 
     69 * In the first step child 4 is eliminated, child 5 becomes the leader.
     70 * In the second step child 2 is eliminated, child 3 becomes the leader.
     71 * In the third step child 5 is eliminated, child 6 becomes the leader.
     72 * In the fourth step child 6 is eliminated, child 7 becomes the leader.
     73 * In the final step child 1 is eliminated, child 3 becomes the leader.