Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<queue>
- using namespace std;
- typedef long long int ll;
- int main()
- {
- int n,w;
- ll k;
- scanf("%d %d %d",&n,&w,&k);
- ll arr[n+1];
- ll maxh = 1;
- for(int i = 1 ; i <= n ; i ++){
- scanf("%lld",&arr[i]);
- if(maxh < arr[i])maxh = arr[i];
- }
- ll l = 0 , r = maxh;
- ll ans = maxh;
- while(l <= r){
- ll m = (l+r)/2;
- queue<pair<int,ll> > q;
- ll sumnow = 0;
- ll cnt = 0;
- // printf("Test m %lld\n",m);
- for(int i = 1 ; i <= n && cnt <= k; i ++){
- if(!q.empty()){
- if(q.front().first+w == i){
- sumnow -= q.front().second;
- q.pop();
- }
- }
- if(arr[i]-sumnow > m){ //need to destroy
- ll dest = (arr[i]-sumnow)-m;
- // printf("Destroy %d %lld \n",i,dest);
- sumnow += dest;
- cnt += dest;
- q.push({i,dest});
- }
- }
- if(cnt <= k){
- ans = m;
- r = m - 1;
- }
- else{
- l = m + 1;
- }
- }
- printf("%lld",ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement