fork download
  1. uses math;
  2. const maxn = 10000;
  3. fi = '';
  4. fo = '';
  5. var n:word;
  6. k:byte;
  7. a: array[1..maxn] of integer;
  8. f: array[0..maxn] of longint;
  9. res:longint;
  10. procedure enter;
  11. var i,j:word;
  12. begin
  13. assign(input,fi);
  14. reset(input);
  15. assign(output,fo);
  16. rewrite(output);
  17. readln(n,k);
  18. f[0]:=0;
  19. res:=0;
  20. for i:=1 to n do
  21. begin
  22. read(a[i]);
  23. f[i]:=trunc(-10e9);
  24. if i=1 then f[i]:=max(0,a[i])
  25. else
  26. for j:=i-1 downto max(0,i-k) do
  27. f[i]:=max(f[i],f[j]+a[i]);
  28. if f[i]>res then res:=f[i];
  29. end;
  30. writeln(res);
  31. close(input);
  32. close(output);
  33. end;
  34. begin
  35. enter;
  36. end.
Success #stdin #stdout 0s 508KB
stdin
Standard input is empty
stdout
0