fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4.  
  5. int a,b,gift[100005],temp;
  6.  
  7. int main () {
  8. scanf ("%d %d", &a, &b);
  9. for (int i=1; i<=a; i++) {
  10. scanf ("%d", &gift[i]);
  11. }
  12.  
  13. int maks = -20000007;
  14.  
  15.  
  16. for (int i=1; i<=a-b+1; i++) {
  17. if (gift[i] <= gift[i-b]) continue;
  18. temp = 0;
  19. for (int j=1; j<=b; j++) {
  20. temp = temp + gift[i+j-1];
  21. }
  22. if (temp > maks) maks = temp;
  23. }
  24.  
  25. printf ("%d\n", maks);
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 3532KB
stdin
6 3
4 2 3 5 7 -1
stdout
15