Advertisement
add1ctus

Untitled

Mar 2nd, 2015
592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <utility>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int n,m,maksimum=0;
  10.     cin>>n>>m;
  11.  
  12.     queue<pair<int, int> > Q;
  13.  
  14.     for(int i=0;i<n;i++)
  15.     {
  16.         int broj,potrebno;
  17.         cin>>broj;
  18.  
  19.         if(i<m%n)
  20.             potrebno=m/n+1;
  21.         else
  22.             potrebno=m/n;
  23.  
  24.         Q.push(make_pair(broj,i));
  25.         int brojac=0;
  26.  
  27.         while(!Q.empty())
  28.         {
  29.             if (brojac+Q.front().first <= potrebno)
  30.             {
  31.                 brojac+=Q.front().first;
  32.                 maksimum=max(maksimum,i-Q.front().second);
  33.                 Q.pop();
  34.             }
  35.             else
  36.             {
  37.                 Q.front().first-=potrebno-brojac;
  38.                 break;
  39.             }
  40.             if(brojac==potrebno)
  41.                 break;
  42.         }
  43.     }
  44.  
  45.     cout<<maksimum;
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement