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