比赛 |
20091112练习 |
评测结果 |
ATAAAAAATT |
题目名称 |
平衡的阵容 |
最终得分 |
70 |
用户昵称 |
rottenwood |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2009-11-12 10:00:22 |
显示代码纯文本
program balance;
var
sum:array[1..50000] of longint;
f:array[1..50000,1..2] of longint;
i,j,k,m,n,temp,ans:longint;
procedure qsort(l,r:longInt);
var
i,j,x,y:longint; s1,ss:longint;
begin
i:=l; j:=r; ss:=f[(l+r) div 2,2];
repeat
while f[i,2]<ss do i:=i+1;
while ss<f[j,2] do j:=j-1;
if i<=j then
begin
y:=f[i,1]; f[i,1]:=f[j,1]; f[j,1]:=y;
y:=f[i,2]; f[i,2]:=f[j,2]; f[j,2]:=y;
i:=i+1; j:=j-1;
end;
until i>j;
if l<j then qsort(l,j);
if i<r then qsort(i,r);
end;
begin
assign(input,'balance.in');reset(input);
assign(output,'balance.out');rewrite(output);
readln(n);
for i:=1 to n do
begin
readln(f[i,1],f[i,2]);
if f[i,1]=0 then f[i,1]:=-1;
end;
qsort(1,n);
////////////////////////////////////////////////////////
temp:=0;
for i:=1 to n do
begin
sum[i]:=temp+f[i,1];
temp:=temp+f[i,1];
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if (sum[i]=sum[j])and(f[j,2]-f[i+1,2]>ans) then ans:=f[j,2]-f[i+1,2];
writeln(ans);
close(output);
end.