求解为什么30分

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 条评论

目前还没有评论...

信息

ID
1165
难度
6
分类
模拟 点击显示
标签
递交数
3238
已通过
939
通过率
29%
被复制
13
上传者