Submission #969909

#TimeUsernameProblemLanguageResultExecution timeMemory
969909uriegRice Hub (IOI11_ricehub)C++17
0 / 100
2 ms604 KiB
#include <bits/stdc++.h> #include "ricehub.h" using namespace std; typedef long long ll; /// for moondance int besthub(int R, int L, int X[], long long B){ vector<ll>x(R), p(R); for(int i=0;i<R;i++){ x[i] = X[i]; p[i] = x[i]; if(i)p[i] += p[i-1]; } int ans = 1; ll sum = 0; int l = 0, r = 0; for(int i =0;i<R;i++){ r = max(r, i); sum = p[r]-p[i] - p[i]*(r-i); sum += p[i]*(i-l+1) - (p[i]-(!l ? 0 : p[l-1])); while(sum > B){ l++; sum = p[r]-p[i] - p[i]*(r-i); sum += p[i]*(i-l+1) - (p[i]-(!l ? 0 : p[l-1])); } while(r<R){ ll new_sum = p[r+1]-p[i] - p[i]*(r+1-i); new_sum += p[i]*(i-l+1) - (p[i]-(!l ? 0 : p[l-1])); if(new_sum <= B){ sum = new_sum; r++; } else{ break; } } ans = max(ans, r-l+1); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...