记录编号 41069 评测结果 AAAAAA
题目名称 [暑假培训2012] 黑叔 最终得分 100
用户昵称 GravatarFangel 是否通过 通过
代码语言 Pascal 运行时间 0.026 s
提交时间 2012-07-20 12:10:41 内存使用 2.68 MiB
显示代码纯文本
program p4;
var
a,b,c,d,t,n:longint;s:string;
q:char;ss:array[0..10000,1..2] of longint;
nam:array[0..10000] of string;
//-----------------------------------------------------------------------------
procedure kp1(x,y:longint);
var
i,j,m,n:longint;
s,q:string;
begin
i:=x;j:=y;m:=ss[(i+j) div 2,1];
repeat
while ss[i,1]<m do inc(i);
while ss[j,1]>m do dec(j);
if i<=j then begin
n:=ss[i,1];ss[i,1]:=ss[j,1];ss[j,1]:=n;
n:=ss[i,2];ss[i,2]:=ss[j,2];ss[j,2]:=n;
q:=nam[i];nam[i]:=nam[j];nam[j]:=q;
inc(i);dec(j);end;
until j<i;
if x<j then kp1(x,j);
if i<y then kp1(i,y);
end;
//--------------------------------------------------------------------------------
procedure kp2(x,y:longint);
var
i,j,n:longint;
s,q:string;
begin
i:=x;j:=y;
s:=nam[(i+j) div 2];
repeat
while nam[i]<s do inc(i);
while nam[j]>s do dec(j);
if i<=j then begin
n:=ss[i,1];ss[i,1]:=ss[j,1];ss[j,1]:=n;
n:=ss[i,2];ss[i,2]:=ss[j,2];ss[j,2]:=n;
q:=nam[i];nam[i]:=nam[j];nam[j]:=q;
inc(i);dec(j);end;
until j<i;
if x<j then kp2(x,j);
if i<y then kp2(i,y);
end;
//-----------------------------------------------------------------------------
begin
assign(input,'hey.in');
reset(input);
assign(output,'hey.out');
rewrite(output);
read(n);
for a:=1 to n do
begin
read(ss[a,1]);
read(q);read(q);
s:='';
while q<>' ' do
begin
s:=s+q;
read(q);
end;
nam[a]:=s;
read(ss[a,2])
end;
//---------------------------------------------------------------------------------

kp1(1,n);

a:=0;b:=0;
while a<=n do
begin
 inc(a);
 if ss[a,1]=ss[a-1,1] then inc(b)
 else begin kp2(a-b-1,a-1);b:=0;end;
end;

b:=0;
for a:=1 to n do
  begin
  if ss[a,1]> b then begin writeln(nam[a],' went out at time ',ss[a,1]);b:=ss[a,1]+ss[a,2];end
                else begin writeln(nam[a],' went out at time ',b);b:=b+ss[a,2];end;
  end;
close(input);
close(output);
end.