比赛 20130725暑期B班1测 评测结果 AAAAAW
题目名称 黑叔 最终得分 83
用户昵称 digital-T 运行时间 0.037 s
代码语言 Pascal 内存使用 2.69 MiB
提交时间 2012-07-18 11:21:24
显示代码纯文本
var
n,i,j,k,time:longint;
t:array[0..10001]of longint;
d:array[0..10001]of longint;
c:array[0..10001]of string;
e:array[0..10001]of boolean;
procedure qsort(l,r:longint);
var
x,y,z,zz:longint;
zzz:string;
begin
x:=l;
y:=r;
z:=t[(x+y)div 2];
repeat
while t[x]<z do inc(x);
while t[y]>z do dec(y);
if x<=y then
 begin
  if ((t[x]=t[y])and(c[x]>c[y]))or(t[x]<>t[y]) then
  begin
  zz:=t[x];
  t[x]:=t[y];
  t[y]:=zz;
  zzz:=c[x];
  c[x]:=c[y];
  c[y]:=zzz;
  zz:=d[x];
  d[x]:=d[y];
  d[y]:=zz;
  end;
  inc(x);
  dec(y);
 end;
until x>y;
if x<r then qsort(x,r);
if l<y then qsort(l,y);
end;
procedure switchin(l,r:longint);
var
ii,jj,kk:longint;
begin
if t[l]<t[l+1] then exit;
if t[l]>t[r] then
 begin
  kk:=t[l];
  for ii:=1 to r-1 do t[ii]:=t[ii+1];
  t[r]:=kk;
  exit;
 end;
for ii:=2 to r-1 do
 if (t[ii]<=t[l])and(t[ii+1]>t[l]) then
  begin
   kk:=t[l];
   for jj:=2 to ii do t[jj-1]:=t[jj];
   t[ii]:=kk;
   exit;
  end;

end;

begin
assign(input,'hey.in');reset(input);
assign(output,'hey.out');rewrite(output);
read(n);
for i:=1 to n do
 begin
  read(t[i]);
  read(c[i]);
  j:=length(c[i]);
  k:=1;
  while (ord(c[i][j])>=48)and(ord(c[i][j])<=57) do
   begin
    d[i]:=d[i]+(ord(c[i][j])-48)*k;
    k:=k*10;
    dec(j);
   end;
  k:=length(c[i])-j+1;
  delete(c[i],j,k);
  delete(c[i],1,1);
 end;
qsort(1,n);

time:=0;
i:=1;
t[0]:=t[1];
t[n+1]:=maxlongint;
fillchar(e,sizeof(e),true);
while i<=n do
begin
  if (time<=t[i])and(t[i]<>t[i+1]) then
   begin
    writeln(c[i],' went out at time ',t[i]);
    time:=t[i]+d[i];
    inc(i);
   end;
  if (time<=t[i])and(t[i]=t[i+1]) then
   begin
    j:=i+1;
    while t[j+1]=t[i] do inc(j);
    switchin(i,j);
    writeln(c[i],' went out at time ',t[i]);
    time:=t[i]+d[i];
    inc(i);
   end;

  if time>t[i] then
   begin
    t[i]:=time;
    j:=i;
    while t[j+1]<=time do
     begin
      inc(j);
      t[j]:=time;
     end;
   end;

end;
close(input);
close(output);
end.