Advertisement
Guest User

Untitled

a guest
May 27th, 2020
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. ll x[300000];
  2. ll pref[300000];
  3. int main(){
  4. ll n, a, b;
  5. cin>>n>>a>>b;
  6. x[0]=pref[0]=0;
  7. for(ll i=1;i<=n;i++){
  8. cin>>x[i];
  9. }
  10. multiset<ll> cur;
  11. pref[1]=x[1];
  12. for(ll i=1;i<=n;i++){
  13. pref[i]=pref[i-1]+x[i];
  14. }
  15. ll ans=-2e18;
  16. for(int i=a;i<=n;i++){
  17. // dbg(i);
  18. cur.insert(pref[i-a]);
  19. if(i>b){
  20. //erase
  21. if(cur.find(pref[i-b-1])!=cur.end())
  22. cur.erase(cur.find(pref[i-b-1]));
  23. }
  24. ans=max(ans, pref[i]-*cur.begin());
  25. }
  26.  
  27. cout<<ans<<'\n';
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement