Pagini recente » Cod sursa (job #1820794) | Cod sursa (job #3171833) | Cod sursa (job #2461795) | Cod sursa (job #383294) | Cod sursa (job #282127)
Cod sursa(job #282127)
type concert=record
int1,int2:longint;
end;
var a:array[1..100000] of concert;
n,suma:longint;
g:text;
procedure qsort(l,r:longint);
var i,j,x1,x2:longint;
aux:concert;
begin
i:=l;
j:=r;
x1:=a[(l+r) div 2].int1;
x2:=a[(l+r) div 2].int2;
repeat
while a[i].int1<x1 do inc(i);
while a[i].int2<x2 do inc(i);
while a[j].int1>x1 do dec(j);
while a[j].int2>x2 do dec(j);
if i<=j then
begin
aux:=a[i];
a[i]:=a[j];
a[j]:=aux;
inc(i);
dec(j);
end;
until i>=j;
if j>l then qsort(l,j);
if i<r then qsort(i,r);
end;
procedure citire;
var f:text;
i:longint;
begin
assign(f,'heavymetal.in'); reset(f);
readln(f,n);
for i:=1 to n do readln(f,a[i].int1,a[i].int2);
close(f);
end;
procedure rezolvare;
var i:longint;
begin
qsort(1,n);
for i:=1 to n-1 do
if a[i].int1<>a[i+1].int1 then suma:=suma+a[i].int2-a[i].int1;
if a[n].int1<>a[n-1].int1 then suma:=suma+a[n].int2-a[n].int1;
end;
procedure afisare;
begin
assign(g,'heavymetal.out'); rewrite(g);
writeln(g,suma);
close(g);
end;
begin
citire;
rezolvare;
afisare;
end.