Pagini recente » Cod sursa (job #645477) | Cod sursa (job #3211794) | Cod sursa (job #3004669) | Cod sursa (job #380267) | Cod sursa (job #187185)
Cod sursa(job #187185)
program stergeri;
var f,g:text;
n,m,k,a,b,p,c2,l1,l2:int64;
i:longint;
begin
assign(f,'stergeri.in');
assign(g,'stergeri.out');
reset(f);
rewrite(g);
read(f,n,m,k);
p:=k;
for i:=1 to m do
begin
read(f,a,b);
if (a>k)then
begin
c2:=b-a+1;
l1:=a;
l2:=b;
end else
begin
p:=p+b-a+1;
if (p>=l1)and(c2>0)then
begin
inc(p,c2);
c2:=0;
end else
if (c2>0)then
begin
dec(l1,b-a+1);
dec(l2,b-a+1);
end;
end;
end;
write(g,p);
close(f);
close(g);
end.