fork download
  1.  
  2.  
  3. #include <bits/stdc++.h>
  4. #define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
  5. #define fi first
  6. #define se second
  7. #define el "\n"
  8. #define pb push_back
  9. #define sz(a) (int)a.size()
  10. #define FILL(a, x) memset(a, x, sizeof(a))
  11.  
  12. using namespace std;
  13. typedef long long ll;
  14. typedef pair<int, int> ii;
  15. const int N = (int)1e6+3;
  16. int n, k;
  17. ll S[N];
  18. ll ans, kq;
  19. int main()
  20. {
  21. ios_base::sync_with_stdio(false);
  22. cin.tie(NULL); cout.tie(NULL);
  23. cin >> n >> k;
  24. FOR(i, 1, n){
  25. int x;
  26. cin >> x;
  27. S[i] = S[i-1] + x;
  28. }
  29. ll ans = -1e18;
  30. FOR(i, k, n){
  31. kq = min(kq, S[i-k]);
  32. ans = max(ans, S[i] - kq);
  33. }
  34. cout << ans;
  35. return 0;
  36. }
  37.  
  38.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty