比赛 |
20091112练习 |
评测结果 |
ATAAAAATTT |
题目名称 |
平衡的阵容 |
最终得分 |
60 |
用户昵称 |
chengyang |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2009-11-12 11:40:41 |
显示代码纯文本
program banlance;
var
a:array[0..50001,1..2]of longint;
i,j,n,k,a1,m,a0,max:longint;
procedure sort(l,r:longint);
var
i,j,x,y,z:longint;
begin
i:=l; j:=r;
x:=a[(l+r)div 2,1];
repeat
while a[i,1]<x do inc(i);
while a[j,1]>x do dec(j);
if not(i>j) then begin
y:=a[i,1]; z:=a[i,2];
a[i,1]:=a[j,1]; a[i,2]:=a[j,2];
a[j,1]:=y; a[j,2]:=z;
inc(i); dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
begin
assign(input,'balance.in');
assign(output,'balance.out');
reset(input); rewrite(output);
readln(n);
fillchar(a,sizeof(a),0);
for i:=1 to n do begin
readln(k,m);
a[i,2]:=k; a[i,1]:=m;
end;
sort(1,n); max:=0;
for i:=1 to n do begin
k:=0;
for j:=i to n do begin
if a[j,2]>0 then inc(k) else dec(k);
if (k=0)and(max<a[j,1]-a[i,1]) then max:=a[j,1]-a[i,1];
end;
end;
writeln(max);
close(input); close(output);
end.