- 火烧赤壁
- 2016-10-05 10:19:28 @
// program houshaochibi;
var i,n,j,long:longint;
a,b:array[1..100000]of longint;
begin
read (n);long:=0;
for i:= 1 to n do
read(a[i],b[i]);
for i:= 1 to n do
for j:= i to n do
begin
if (a[j]<b[i]) and (b[j]>b[i]) and(a[j]>a[i])
then begin
b[i]:=b[j];
a[j]:=b[j];
end;
if (a[j]<a[i]) and (b[j]<b[i]) and(b[j]>a[i])
then begin
a[i]:=a[j];
b[j]:=a[j];
end;
end;
for i:= 1 to n do
long:=long+(b[i]-a[i]);
writeln(long);
end.
0 条评论
目前还没有评论...