fork download
  1. Program machine;
  2. Uses Math;
  3. { constraints }
  4. const
  5. MAXD = 1000;
  6. MAXY = 1000000;
  7. { input data }
  8. var
  9. C, D, Y, i,j,k,w: longint;
  10. // Warning! M and P are 1-based
  11. M, P : array[1..MAXD] of longint;
  12. bilancio : array[0..MAXD] of longint;
  13. costo, indice : array[0..MAXY] of longint;
  14. begin
  15.  
  16. (* assign(input, 'input.txt'); reset(input);
  17.   assign(output, 'output.txt'); rewrite(output);*)
  18.  
  19.  
  20. readln(C, D, Y);
  21. // Warning! M and P are 1-based
  22. for i:=1 to D do
  23. read(M[i]);
  24. readln();
  25. for i:=1 to D do
  26. read(P[i]);
  27. readln();
  28. bilancio[1]:=C+M[1]-P[1];
  29. { insert your code here }
  30. bilancio[0]:=0; costo[0]:=0; w:=0;
  31. for i:=2 to D do bilancio[i]:=bilancio[i-1]+M[i]-P[i]+ P[i-1];
  32. for i:=1 to Y do costo[i]:=2147483647;
  33.  
  34. for i:= 0 to D do
  35. begin
  36. for j:=1 to D do
  37. begin
  38. if (i+j <= Y) then
  39. begin
  40. if (costo[i] + bilancio[j])<=costo[i+j] then
  41. costo[i+j] := costo[i] + bilancio[j];
  42. writeln(costo[i+j]) ;
  43. end;
  44. end;
  45.  
  46. if ((i <= Y) and (costo[i] = bilancio[i])) then
  47. begin
  48. indice[w] := i;
  49. w := w+1;
  50. end;
  51. end;
  52. for i:= D to Y -D -2 do
  53. begin
  54. for k:=0 to w-1 do
  55. begin
  56. j := indice[k];
  57.  
  58. if (costo[i+j] >= costo[i] + bilancio[j]) then
  59. costo[i+j] := costo[i] + bilancio[j];
  60.  
  61.  
  62. end;
  63. end;
  64.  
  65. writeln(costo[Y-2]); { print result }
  66. end.
Success #stdin #stdout 0s 5320KB
stdin
10 5 8
1 2 2 5 2
5 4 3 5 4
stdout
6
9
12
15
18
9
12
15
18
24
12
15
18
24
27
15
18
24
27
30
18
24
27
30
24
27
30
24