记录编号 7350 评测结果 AAAAAAAAAA
题目名称 [USACO Mar03] 奶酪工厂 最终得分 100
用户昵称 Gravatarzhai 是否通过 通过
代码语言 Pascal 运行时间 0.075 s
提交时间 2008-11-09 15:59:56 内存使用 0.11 MiB
显示代码纯文本
program factory;
  type
    sx=array[0..15]of integer;
  var
    f1,f2:text;
    n,s,y:integer;
    c,x:longint;
    min:sx;
    procedure jia(var min:sx;m:longint);
      var
        i,j,la,lb:integer;
        a,b,c:sx;
      begin
        lb:=1;
        fillchar(a,sizeof(a),0);
        fillchar(c,sizeof(c),0);
        fillchar(b,sizeof(b),0);
        repeat
          b[lb]:=m mod 10;
          m:=m div 10;
          inc(lb);
        until m=0;
        dec(lb);
        b[0]:=lb;
        la:=min[0];
        if lb<la then lb:=la;
        for i:=1 to la do a[i]:=min[la-i+1];
        for i:=1 to lb do c[i]:=a[i]+b[i];
        for i:=1 to lb do begin
          c[i+1]:=c[i+1]+c[i]div 10;
          c[i]:=c[i]mod 10;
        end;
        if c[i+1]<>0 then inc(i);
        min[0]:=i;
        for i:=1 to min[0] do min[i]:=c[min[0]-i+1];
      end;
    procedure ini;
      var
        m:longint;
      begin
        assign(f1,'factory.in');reset(f1);
        assign(f2,'factory.out');rewrite(f2);
        readln(f1,n,s);
        readln(f1,c,y);
        x:=c;
        m:=x*y;
        fillchar(min,sizeof(min),0);
        jia(min,m);
      end;
    procedure main;
      var
        i,j:integer;
        m:longint;
      begin
        for i:=2 to n do begin
          readln(f1,c,y);
          inc(x,s);
          if c<x then x:=c;
          m:=x*y;
          jia(min,m);
        end;
      end;
    procedure pr;
      var
        i:integer;
      begin
        for i:=1 to min[0]do write(f2,min[i]);
      end;
  begin
    ini;
    main;
    pr;
    close(f1);
    close(f2);
  end.