记录编号 40670 评测结果 AAWWWW
题目名称 [暑假培训2012] 黑叔 最终得分 33
用户昵称 GravatarH J H 是否通过 未通过
代码语言 Pascal 运行时间 0.037 s
提交时间 2012-07-18 16:03:44 内存使用 2.72 MiB
显示代码纯文本
var
s:array[1..10000,1..3]of longint;
na:array[1..10000]of string;
i,n,k,t:longint;
c:char;


function bj(a,b:longint):integer;
var m:integer;
begin
if a=b then begin bj:=0; exit; end;
if s[a,1]<s[b,1] then begin bj:=1; exit; end;
if s[a,1]>s[b,1] then begin bj:=2; exit; end;

if s[a,1]=s[b,1] then
                 if na[a]<na[b] then begin bj:=1; exit; end
                 else if na[a]>na[b] then begin bj:=2; exit; end;
end;





procedure kp(x,y:longint);
var i,j,m,n:longint;
    q:string;
begin
i:=x; j:=y;
m:=(x+y) div 2;

repeat
while bj(i,m)=1 do inc(i);
while bj(j,m)=2 do dec(j);

if i<=j then begin
n:=s[i,1]; s[i,1]:=s[j,1]; s[j,1]:=n;
n:=s[i,2]; s[i,2]:=s[j,2]; s[j,2]:=n;
q:=na[i]; na[i]:=na[j]; na[j]:=q;
inc(i); dec(j); end;

until i>j;

if j>x then kp(x,j);
if i<y then kp(i,y);
end;

begin
assign(input,'hey.in');
reset(input);
assign(output,'hey.out');
rewrite(output);
readln(n);
fillchar(na,sizeof(na),' ');
fillchar(s,sizeof(s),0);
for i:=1 to n do na[i]:='';
for i:=1 to n do
    begin
    read(s[i,1]);
    k:=0; read(c);read(c);
    while c<>' ' do
          begin
          na[i]:=na[i]+c;
          read(c);
          end;
    read(s[i,2]);
    end;
kp(1,n);
t:=s[1,1];
for i:=1 to n do
begin
if s[i,1]>t then t:=s[i,1];
write(na[i],' went out at time ',t);
t:=t+s[i,2];
if i<>n then writeln;
end;
close(input);close(output);
end.