var n, m : longint; i, j : longint; trawa, dpop : int64; licz, liczN : array[1..500000] of longint; d, b : array[1..500000] of longint; begin for i := 1 to 500000 do begin licz[i] := 0; liczN[i] := 0; end; readln(n,m); for i := 1 to n do begin read(licz[i]); end; for i := 1 to m do begin trawa := 0; read(d[i],b[i]); end; dpop := 0; for i := 1 to m do begin trawa := 0; for j := 1 to n do begin liczN[j] := liczN[j] + ((d[i] - dpop) * licz[j]); // writeln(b[i],':',liczN[j],':',d[i]-dpop); if b[i] < liczN[j] then begin trawa := trawa + liczN[j] - b[i]; // writeln(trawa); liczN[j] := b[i]; end; // dpop := d[i]; end; dpop := d[i]; writeln(trawa); end; end.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | var n, m : longint; i, j : longint; trawa, dpop : int64; licz, liczN : array[1..500000] of longint; d, b : array[1..500000] of longint; begin for i := 1 to 500000 do begin licz[i] := 0; liczN[i] := 0; end; readln(n,m); for i := 1 to n do begin read(licz[i]); end; for i := 1 to m do begin trawa := 0; read(d[i],b[i]); end; dpop := 0; for i := 1 to m do begin trawa := 0; for j := 1 to n do begin liczN[j] := liczN[j] + ((d[i] - dpop) * licz[j]); // writeln(b[i],':',liczN[j],':',d[i]-dpop); if b[i] < liczN[j] then begin trawa := trawa + liczN[j] - b[i]; // writeln(trawa); liczN[j] := b[i]; end; // dpop := d[i]; end; dpop := d[i]; writeln(trawa); end; end. |