Solution report
There is nothing to say. If it is larger than m, it will be placed in the back ,,,
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;struct node{ int x,cd;}num[1000000];int main(){ int n,m,c; cin>>n>>m; int i; for(i=0;i<n;i++) { cin>>num[i].cd; num[i].x=i+1; } for(i=0;i<n;i++) { if(num[i].cd>m) { num[i].cd-=m; num[n++]=num[i]; } } printf("%d\n",num[n-1].x); return 0;}
Jzzhu and childrentime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
There areNChildren in jzzhu's school. jzzhu is going to give some candies to them. Let's number all the children from 1N.I-Th child wants to get at leastAICandies.
Jzzhu asks children to line up. Initially,I-Th child stands atI-Th place of the line. Then jzzhu start distribution of the candies. He follows the algorithm:
- GiveMCandies to the first child of the line.
- If this child still haven' t got enough candies, then the child goes to the end of the line, else the child go home.
- Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. jzzhu wants to know, which child will be the last in this order?
Input
The first line contains two integersN,?M(1? ≤?N? ≤? 100; 1? ≤?M? ≤? (100). The second line containsNIntegersA1 ,?A2 ,?...,?AN(1? ≤?AI? ≤? 100 ).
Output
Output a single integer, representing the number of the last child.
Sample test (s) Input
5 21 3 1 4 2
Output
4
Input
6 41 1 2 2 3 3
Output
6
Note
Let's consider the first sample.
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.
Child 4 is the last one who goes home.