比赛 noip20081103 评测结果 AAAAAAAAAA
题目名称 奶酪工厂 最终得分 100
用户昵称 thegy 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-03 19:42:16
显示代码纯文本
program factory;
type
  node=record
         key:longint;
       end;
var
  fin,fout:text;
  heap:array[1..10000]of node;
  ans:array[1..10000]of longint;
  ans2:array[1..10000]of longint;
  n,s,a,heaptail,i:longint;
  ans0:int64;
procedure exchange(i,j:longint);
var
  t:longint;
begin
  t:=heap[i].key;
  heap[i].key:=heap[j].key;
  heap[j].key:=t;
end;
procedure up(x:longint);
begin
  if x=1 then exit;
  if heap[x].key<heap[x div 2].key then begin
    exchange(x,x div 2);
    up(x div 2);
  end;
end;
begin
  assign(fin,'factory.in'); reset(fin);
  assign(fout,'factory.out'); rewrite(fout);
  read(fin,n,s);
  read(fin,a,ans2[1]);
  heap[1].key:=a;
  heaptail:=1;
  ans[1]:=a;
  for i:=2 to n do begin
    read(fin,a,ans2[i]);
    inc(heaptail);
    heap[heaptail].key:=a-s*(i-1);
    up(heaptail);
    ans[i]:=heap[1].key;
  end;
  ans0:=0;
  for i:=1 to n do begin
    ans0:=ans0+(ans[i]+(i-1)*s)*ans2[i];
  end;
  writeln(fout,ans0);
  close(fin);
  close(fout);
end.