Advertisement
a53

KSum3

a53
Nov 22nd, 2021
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1.  
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. int n,k,w;
  5. long long s[1000005];
  6. deque<int>q;
  7. int main(){
  8. ios_base::sync_with_stdio(false);
  9. cin.tie(nullptr);
  10. cin>>n>>k>>w;
  11. for(int i=1;i<=n;i++)cin>>s[i],s[i]+=s[i-1];
  12. long long mx(s[k]);
  13. for(int i=k;i<=n;i++){
  14. if(q.front()==i-w-1)q.pop_front();
  15. while(!q.empty()&&s[q.back()]>s[i-k])q.pop_back();
  16. q.push_back(i-k);
  17. mx=max(mx,s[i]-s[q.front()]);
  18. }
  19. cout<<mx;
  20. return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement