fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int MAXN = 2e5 + 7;
  4. long long A[MAXN], n, a, b;
  5. long long ans = LLONG_MIN;
  6. long long pre[MAXN];
  7.  
  8. void sub1(){
  9. for(int R = a ; R <= b; R++){
  10. for(int L = 1; L + R - 1 <= n; L++){
  11. long long sum = 0;
  12. for(int i = L; i < L + R; i++) sum += A[i];
  13. ans = max(ans , sum);
  14. }
  15. }
  16. cout << ans;
  17. }
  18.  
  19. void sub2(){
  20. for(int L = 1; L + a - 1 <= n; L++){
  21. for(int R = L + a - 1; R <= L + b - 1; R++){
  22. if(R > n) break;
  23. long long sum = pre[R] - pre[L - 1];
  24. ans = max(ans, sum);
  25. }
  26. }
  27. cout << ans;
  28. }
  29.  
  30. int main(){
  31. ios_base::sync_with_stdio(0);
  32. cin.tie(0);
  33. cout.tie(0);
  34.  
  35. cin >> n >> a >> b;
  36. for(int i = 1; i <= n; i++){
  37. cin >> A[i];
  38. pre[i] = pre[i - 1] + A[i];
  39. }
  40. if(n <= 100) sub1();
  41. else if(n <= 10000) sub2();
  42. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty