fork download
  1. program muffin;
  2. { constraints }
  3. const
  4. MAXN = 1000000;
  5.  
  6. { input data }
  7. var
  8. N, K, i, Ans, sapore : longint;
  9. V : array[0..MAXN-1] of longint;
  10.  
  11. begin
  12. {
  13.   uncomment the following lines if you want to read/write from files
  14.   assign(input, 'input.txt'); reset(input);
  15.   assign(output, 'output.txt'); rewrite(output);
  16. }
  17.  
  18. readln(N, K);
  19. for i:=0 to N-1 do
  20. read(V[i]);
  21. readln;
  22. sapore:=0; Ans:=0;
  23. for i:=0 to K-1 do sapore:=sapore+V[i];
  24. i:=K; Ans:=sapore;
  25. while i<N do
  26. begin
  27. sapore:=sapore-V[i-k]+V[i];
  28. if sapore>Ans then Ans:=sapore;
  29. i:=i+1;
  30. end;
  31.  
  32. writeln(Ans); { answer }
  33. end.
  34.  
Success #stdin #stdout 0s 5312KB
stdin
5 2
1 -2 4 -8 16
stdout
8