a53

Zen

a53
Jan 26th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <deque>
  4. using namespace std;
  5.  
  6. ifstream fin("zen.in");
  7. ofstream fout("zen.out");
  8.  
  9. #define mp make_pair
  10. #define f first
  11. #define s second
  12.  
  13. deque <pair<long long,int> > q;
  14. long long n,k,i,x;
  15.  
  16. int main()
  17. {
  18. fin>>n>>k;
  19. q.push_back(mp(0,0));
  20. for(i=1; i<=n; ++i)
  21. {
  22. fin>>x;
  23.  
  24. while(q.size() && q.front().s<i-k)
  25. q.pop_front();
  26. x+=q.front().f;
  27. while(q.size() && q.back().f>=x)
  28. q.pop_back();
  29. q.push_back(mp(x,i));
  30. }
  31. fout<<x;
  32. }
Add Comment
Please, Sign In to add comment