Codeforces 450A. Jzzhu and Children Solution
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int m,n,i,sz,ans,f;
- queue<int>q;
- map<int,int>mp;
- cin>>n>>m;
- int a[n+9];
- for(i=0; i<n; i++)
- {
- cin>>a[i];
- q.push(i);
- }
- while(!q.empty())
- {
- f=q.front();
- ans=f+1;
- if(mp[f]+m>=a[f])
- q.pop();
- else
- {
- q.pop();
- mp[f]+=m;
- q.push(f);
- }
- }
- cout<<ans<<endl;
- }
No comments