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

    1. #include <bits/stdc++.h>
    2. using namespace std;
    3. int main()
    4. {
    5. int m,n,i,sz,ans,f;
    6. queue<int>q;
    7. map<int,int>mp;
    8. cin>>n>>m;
    9. int a[n+9];
    10. for(i=0; i<n; i++)
    11. {
    12. cin>>a[i];
    13. q.push(i);
    14. }
    15.  
    16. while(!q.empty())
    17. {
    18. f=q.front();
    19. ans=f+1;
    20. if(mp[f]+m>=a[f])
    21. q.pop();
    22. else
    23. {
    24. q.pop();
    25. mp[f]+=m;
    26. q.push(f);
    27.  
    28. }
    29.  
    30. }
    31. cout<<ans<<endl;
    32. }
    33.  

    No comments

    Most View Post

    Recent post

    Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

        Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

    Powered by Blogger.