比赛 20130725暑期B班1测 评测结果 AAAAAT
题目名称 黑叔 最终得分 83
用户昵称 如烟 运行时间 1.007 s
代码语言 Pascal 内存使用 0.49 MiB
提交时间 2012-07-18 11:28:00
显示代码纯文本
type
   integer=longint;
var
    i,j,keyword,temp,n,k,z,m,t:integer;
    a,d:array [0..10000] of integer;
    c:Array[0..10000] of string[25];
    s,p:string;
procedure qsort(x,y:integer);
begin
  if x<y then
   begin
     keyword:=a[x];
     s:=c[x];
     i:=x;
     j:=n;
     while i<>j do
      begin
        while (a[j]>keyword) or ((a[j]=keyword)and(c[j]>=s)) do
         begin
           j:=j-1;
           if i=j then break;
        end;
        if (a[j]<keyword) then
         begin
           temp:=a[i];
           a[i]:=a[j];
           a[j]:=temp;
           temp:=d[i];
           d[i]:=d[j];
           d[j]:=temp;
           p:=c[i];
           c[i]:=c[j];
           c[j]:=p;
        end;
        if i=j then break;
        while (a[i]<keyword)or((a[i]=keyword)and(c[i]<=s)) do
         begin
           i:=i+1;
           if i=j then break;
        end;
        if(a[i]>keyword)then
         begin
           temp:=a[i];
           a[i]:=a[j];
           a[j]:=temp;
           temp:=d[i];
           d[i]:=d[j];
           d[j]:=temp;
           p:=c[i];
           c[i]:=c[j];
           c[j]:=p;
        end;
     end;
  qsort(x,j);
  qsort(j+1,y);
  end;
end;
begin
 assign(input,'hey.in');
 reset(input);
 assign(output,'hey.out');
 rewrite(output);
 readln(n);
 for i:=1 to n do
  begin
  readln(s);
  j:=0;k:=0;
  repeat
   j:=j+1;
   if k=2 then  begin k:=k+1;val(s,d[i],temp);end;
   if (s[j]=' ')and (k<2) then
                           begin
                           k:=k+1;
                           p:=copy(s,1,j-1);
                           delete(s,1,j);
                           j:=0;
                           if k=1 then val(p,a[i],temp);
                           if k=2 then c[i]:=p;
                           end;
  until k=3;
 end;
 qsort(1,n);
 d[1]:=a[1]+d[1];
 write(c[1],' went out at time ',a[1]);writeln;
 for i:=2 to n do
  if d[i-1]<a[i] then begin write(c[i],' went out at time ',a[i]);writeln;d[i]:=a[i]+d[i];end
                      else begin write(c[i],' went out at time ',d[i-1]);writeln;d[i]:=d[i-1]+d[i];end;
close(input);
close(output);
end.