fork download
  1. program rifornimenti;
  2. const
  3. MAXN = 1000000;
  4.  
  5. { input data }
  6. var
  7. N, i,h : longint;
  8. P : array[0..MAXN-1] of longint;
  9. G : array[0..MAXN-1] of longint;
  10. costopiatti : array[0..MAXN-1] of int64;
  11. spesaminima : int64;
  12. begin
  13. (*assign(input, 'input.txt'); reset(input);
  14.   assign(output, 'output.txt'); rewrite(output);*)
  15. readln(N);
  16. for i:=0 to N-1 do read(P[i]);
  17. readln;
  18. for i:=0 to N-1 do read(G[i]);
  19. readln;
  20. for i:=0 to N-1 do costopiatti[i]:=G[i]*P[i];
  21. spesaminima:=costopiatti[0];
  22. i:=0; h:=1;
  23. while i<N do
  24. begin
  25. while (h<=N-1) do
  26. begin
  27. if spesaminima+P[i]*G[h]<=spesaminima+costopiatti[h] then spesaminima:=spesaminima+P[i]*g[h]
  28. else break;
  29. h:=h+1;
  30. end;
  31.  
  32. i:=h; writeln (i,' ',h);
  33. end;
  34. writeln(spesaminima); { print result }
  35. end.
Success #stdin #stdout 0.01s 5284KB
stdin
5
10 30 2 10 1
10 10 10 10 10
stdout
2 2
4 4
5 5
250