记录编号 33327 评测结果 AAAAAAAAAA
题目名称 韩国明星 最终得分 100
用户昵称 GravatarDes. 是否通过 通过
代码语言 Pascal 运行时间 1.755 s
提交时间 2011-11-10 12:18:20 内存使用 0.88 MiB
显示代码纯文本
program star;
var a:array[1..100000]of ansistring;
    b:array[1..100000]of longint;
    t,k,m,n,i,j:longint;
    s:ansistring;
function search(l,r:longint):longint;
var t,k,j:longint;
begin
if l=r then  exit(l);
k:=(l+r)div 2;
if a[k]<s then exit(search(k+1,r))
else exit(search(l,k));
end;
procedure qsorta(l,r:longint);
var i,j,k:longint;
    m,c:ansistring;
begin
k:=(l+r)div 2;
m:=a[k];
i:=l;
j:=r;
repeat
  while a[i]<m do inc(i);
  while a[j]>m do dec(j);
  if i<=j then
    begin
      c:=a[i];
      a[i]:=a[j];
      a[j]:=c;
      k:=b[i];
      b[i]:=b[j];
      b[j]:=k;
      inc(i);
      dec(j);
    end;
until i>j;
if i<r then qsorta(i,r);
if l<j then qsorta(l,j);
end;
procedure qsortb(l,r:longint);
var i,j,k,m:longint;
    c:ansistring;
begin
k:=(l+r)div 2;
m:=b[k];
i:=l;
j:=r;
repeat
  while b[i]<m do inc(i);
  while b[j]>m do dec(j);
  if i<=j then
    begin
      c:=a[i];
      a[i]:=a[j];
      a[j]:=c;
      k:=b[i];
      b[i]:=b[j];
      b[j]:=k;
      inc(i);
      dec(j);
    end;
until i>j;
if i<r then qsortb(i,r);
if l<j then qsortb(l,j);
end;
begin
assign(input,'star.in');
reset(input);
assign(output,'star.out');
rewrite(output);
readln(n);
for t:=1 to n do
  readln(a[t]);
qsorta(1,n);
readln(m);
for t:=1 to m do
  begin
    readln(s);
    k:=search(1,n);
    readln(i);
    b[k]:=b[k]+i;
  end;
qsortb(1,n);
for t:=n downto 1 do
  begin
    writeln(a[t]);
    writeln(b[t]);
  end;
close(output);
end.