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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
program Siano;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes;

Type TTab=Array[0..500000] of QWord;

Var Speed:TTab;
    Field:TTab;
    CountField : LongWord;
    CountTime  : LongWord;


Procedure ReadTest;
Var L1, Loop : LongWord;
    Height, Last, Time, R : QWord;
    Sum : QWord;
Begin
   ReadLn( CountField, CountTime );
   For Loop:=1 to CountField do Begin
      Read( Speed[Loop] );
   End;
   Last:=0;
   For Loop:=1 to CountTime do Begin
      Read( Time, Height );
      R:=Time-Last;
      Last:=Time;
      Sum :=0;
      For L1:=1 to CountField do Begin
         Field[L1]:=Field[L1]+QWord(QWord(Speed[L1])*QWord(R));
         If Field[L1]>Height Then Begin
            Sum:=Sum+Field[L1]-Height;
            Field[L1]:=Height;
         End;
      End;
      WriteLn( Sum );
   End;
End;

begin
  ReadTest;
end.


{
4 4
1 2 4 3
1 1
2 2
3 0
4 4
}