1. 程式人生 > >codeforces 450A Jzzhu and Children

codeforces 450A Jzzhu and Children

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.

#include <iostream>
#include <cstring>
using namespace std;
int main(){
    int m,n,ans,maxx=-1,x;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>x;
        int j=x%m==0?x/m:(x/m+1);
        if(j>=maxx){
            maxx=j;
            ans=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}