Guest User

Untitled

a guest
May 27th, 2020
52
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using ll=long long;
  3. using namespace std;
  4. ll x[300000];
  5. ll pref[300000];
  6. int main(){
  7. ll n, a, b;
  8. cin>>n>>a>>b;
  9. x[0]=pref[0]=0;
  10. for(ll i=1;i<=n;i++){
  11. cin>>x[i];
  12. }
  13. multiset<ll, greater<ll> > cur;
  14. pref[1]=x[1];
  15. for(ll i=1;i<=n;i++){
  16. pref[i]=pref[i-1]+x[i];
  17. }
  18. for(int i=1;i<=n;i++){
  19. cout<<pref[i]<<" ";
  20. }
  21. for(ll i=a;i<=b and i<=n;i++){
  22. cur.insert(pref[i]);
  23. }
  24. ll answer=*cur.begin();
  25. for(ll i=1;i+a<=n;i++){
  26. if(cur.find(pref[i+a-1])!=cur.end())
  27. cur.erase(cur.find(pref[i+a-1]));
  28. if(i+b<=n){
  29. cur.insert(pref[i+b]);
  30. }
  31. answer=max(answer, *cur.begin()-pref[i]);
  32. }
  33. cout<<answer<<'\n';
  34. }
RAW Paste Data