比赛 20120413 评测结果 AWWWWWWWWTWA
题目名称 工作进度 最终得分 16
用户昵称 wo shi 刘畅 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2012-04-13 20:37:40
显示代码纯文本
var
  n,i,two,one,t,up,down:longint;
  a,b,c,d:array[0..1000000]of longint;
  ans:int64;

procedure sort(l,r:longint);
var
  i,j,x,y,z:longint;
begin
  i:=l;
  j:=r;
  x:=a[(l+r) div 2];
  y:=b[(l+r) div 2];
  repeat
    while (a[i]<x)or((a[i]=x)and(b[i]<y)) do inc(i);
    while (x<a[j])or((x=a[j])and(y<b[j])) do dec(j);
    if i<=j then
    begin
      z:=a[i];
      a[i]:=a[j];
      a[j]:=z;

      z:=b[i];
      b[i]:=b[j];
      b[j]:=z;
      inc(i);
      dec(j);
    end;
  until i>j;
  if i<r then sort(i,r);
  if l<j then sort(l,j);
end;

begin
  assign(input,'joba.in'); reset(input);
  assign(output,'joba.out'); rewrite(output);
  readln(n);
  for i:=1 to n do
    readln(a[i],b[i]);
  sort(1,n);
  t:=1;
  c[1]:=a[1];
  for i:=2 to n do
  if a[i]<>a[i-1] then
  begin
    inc(t);
    c[t]:=a[i];
    d[t-1]:=i-1;
  end;
  d[t]:=n;
  ans:=0;
  two:=n;
  for one:=t downto 1 do
  begin
    up:=two;
    down:=two-(c[one]-c[one-1])+1;
    for i:=up downto down do inc(ans,b[i]);
    two:=d[one-1];
  end;
  writeln(ans);
  close(input);
  close(output);
end.