codeforces-scrape

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

450A.md (1853B)


      1 Source: https://codeforces.com/problemset/problem/450/A
      2 
      3 A. Jzzhu and Children
      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 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
     22 
     23 Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
     24 
     25 1. Give *m* candies to the first child of the line.
     26 2. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home.
     27 3. Repeat the first two steps while the line is not empty.
     28 
     29 Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
     30 
     31 Input
     32 
     33 The first line contains two integers *n*, *m* (1 ≤ *n* ≤ 100; 1 ≤ *m* ≤ 100). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 100).
     34 
     35 Output
     36 
     37 Output a single integer, representing the number of the last child.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 5 2  
     45 1 3 1 4 2
     46 ```
     47 
     48 Output
     49 
     50 ```
     51 4
     52 ```
     53 
     54 Input
     55 
     56 ```
     57 6 4  
     58 1 1 2 2 3 3
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 6
     65 ```
     66 
     67 Note
     68 
     69 Let's consider the first sample.
     70 
     71 Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
     72 
     73 Child 4 is the last one who goes home.