记录编号 6807 评测结果 AAAAAAAAAA
题目名称 [USACO Mar03] 奶酪工厂 最终得分 100
用户昵称 Gravatar逆水行舟 是否通过 通过
代码语言 Pascal 运行时间 1.393 s
提交时间 2008-11-04 17:55:06 内存使用 1.64 MiB
显示代码纯文本
var
  n,s,a,sum,i,j,k,h:longint;
  c,y,b,m:array[1..100000]of longint;
  fin,fout:text;
begin
  assign(fin,'factory.in');reset(fin);
  assign(fout,'factory.out');rewrite(fout);
  read(fin,n,s);
  for i:=1 to n do
    read(fin,c[i],y[i]);
  for i:=2 to n do begin
    a:=s;j:=0;
    repeat
      inc(j);
      if c[i]-a>c[i-j] then c[i]:=c[i-j]+a;
      a:=a+s;
    until i-j=1;
  end; a:=10;j:=0;
  sum:=c[1]*y[1];
  repeat
  inc(j);
  b[j]:=sum mod a;
  sum:=sum div a;
  until sum=0;
  for i:=2 to n do
    begin
    sum:=c[i]*y[i];k:=0;
    repeat
      inc(k);
      m[k]:=sum mod a;
      sum:=sum div a;
    until sum=0;
    if k>j then j:=k;
    for h:=1 to j do
      begin
        if b[h]+m[h]>=10 then b[h+1]:=b[h+1]+1;
        b[h]:=(b[h]+m[h]) mod 10;
      end;
    if b[j+1]=1 then inc(j);
    end;
  for i:=j downto 1 do
  write(fout,b[i]);
  close(fin);
  close(fout);
end.