3 last
,now
:array [-1001..1001] of boolean;
4 a
,b
:array [0..1001] of longint;
7 function up(i
,time
:longint):boolean;
9 time
:=time
mod (a
[i
]+b
[i
]);
10 if (time
>=1) and (time
<=a
[i
]) then exit(true) else exit(false);
15 for i
:=1 to n
do readln(a
[i
],b
[i
]);
20 if last
[n
+1] then begin writeln(time
-1); close(input
); close(output
); halt
; end;
21 fillchar(now
,sizeof(now
),false);
23 if (i
=0) or (i
=n
+1) or (up(i
,time
)) then
25 if (last
[j
]) and (j
>=0) and (j
<=n
+1) then
32 until (time
>2520) or (not f
);
33 if not f
then writeln('NO');