Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <utility>
- using namespace std;
- int main()
- {
- int n,m,maksimum=0;
- cin>>n>>m;
- queue<pair<int, int> > Q;
- for(int i=0;i<n;i++)
- {
- int broj,potrebno;
- cin>>broj;
- if(i<m%n)
- potrebno=m/n+1;
- else
- potrebno=m/n;
- Q.push(make_pair(broj,i));
- int brojac=0;
- while(!Q.empty())
- {
- if (brojac+Q.front().first <= potrebno)
- {
- brojac+=Q.front().first;
- maksimum=max(maksimum,i-Q.front().second);
- Q.pop();
- }
- else
- {
- Q.front().first-=potrebno-brojac;
- break;
- }
- if(brojac==potrebno)
- break;
- }
- }
- cout<<maksimum;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement