- 火烧赤壁
- 2013-09-04 21:07:40 @
var
n,i,ans:longint;
a,b:array[0..20000] of longint;
procedure qsort(l,r:longint);
var
i,j,temp,mid:longint;
begin
i:=l; j:=r;
mid:=(a[i]+a[j]) shr 1;
repeat
while a[i]<mid do inc(i);
while a[j]>mid do dec(j);
if i<=j then
begin
temp:=a[i]; a[i]:=a[j]; a[j]:=temp;
temp:=b[i]; b[i]:=b[j]; b[j]:=temp;
inc(i); dec(j);
end;
until i>j;
if l<j then qsort(l,j);
if i<r then qsort(i,r);
end;
begin
readln(n);
b[0]:=-maxlongint;
for i:=1 to n do
read(a[i],b[i]);
qsort(1,n);
for i:=1 to n do
begin
if a[i]<b[i-1] then a[i]:=b[i-1];
if a[i]>b[i] then a[i]:=b[i];
end;
for i:=1 to n do
ans:=ans+b[i]-a[i];
writeln(ans);
end.
0 条评论
目前还没有评论...