记录编号 6755 评测结果 AAAAAAAAAA
题目名称 [USACO Mar03] 奶酪工厂 最终得分 100
用户昵称 GravatarMayLava 是否通过 通过
代码语言 Pascal 运行时间 0.038 s
提交时间 2008-11-04 14:49:05 内存使用 0.19 MiB
显示代码纯文本
program MayLava;
var
 a,b:array[1..10001]of longint;
 n,s:longint;
 sum,store:int64;
procedure start;
 var
  f:text;
  i:longint;
 begin
  assign(f,'factory.in');
  reset(f);
  readln(f,n,s);
  for i:=1 to n do
   readln(f,a[i],b[i]);
  close(f);
  sum:=0;
 end;
procedure main;
 var
  i,j:longint;
 begin
  for i:=1 to n do begin
   sum:=sum+store*s;
   if store>=b[i] then store:=store-b[i]
   else begin
    sum:=sum+a[i]*b[i];
    j:=1;
    while a[i]+s*j<a[i+j] do begin
      store:=store+b[i+j];
      sum:=sum+a[i]*b[i+j];
      inc(j);
    end;
   end;
  end;
 end;
procedure print;
 var
  f:text;
 begin
  assign(f,'factory.out');
  rewrite(f);
  writeln(f,sum);
  close(f);
 end;
BEGIN
 start;
 main;
 print;
END.