比赛 noip20081103 评测结果 AWAAWWWWWA
题目名称 奶酪工厂 最终得分 40
用户昵称 cuixiaofei 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-03 21:54:07
显示代码纯文本
//na                            :cuixiaofei;
//da                            :08_11_03;
program factory;
  type
    sss                         =record
                      biao,shu,ge,chan:longint;
                                end;
  var
    n,s                         :longint;
    a                           :array[1..10000] of sss;
    f1,f2                       :text;
  procedure init;
    var
      i                         :longint;
  begin
    assign(f1,'factory.in');
    reset(f1);
    assign(f2,'factory.out');
    rewrite(f2);
    fillchar(a,sizeof(a),0);
    readln(f1,n,s);
    for i:=1 to n do
      begin
        readln(f1,a[i].shu,a[i].ge);
        a[i].chan:=a[i].shu*a[i].ge;
      end;
  end;
  procedure main;
    var
      i,j,t,huan                :longint;
    begin
      for i:=1 to n do
        begin
          t:=a[i].chan;
          huan:=i;
          for j:=1 to i-1 do
            if t>((i-j)*s+a[j].shu)*a[i].ge then
              begin
                huan:=j;
                t:=((i-j)*s+a[j].shu)*a[i].ge;
                a[i].biao:=1;
              end;
          if huan<>i then
            begin
              a[huan].biao:=0;
              a[huan].chan:=a[huan].chan+t;
              a[i].biao:=1;
              a[i].chan:=0;
            end;
        end;
    end;
  procedure print;
    var
      i,min                      :longint;
  begin
    min:=0;
    for i:=1 to n do
      if a[i].biao=0 then
      min:=min+a[i].chan;
    writeln(f2,min);
    close(f1);
    close(f2);
  end;
  begin
    init;
    main;
    print;
  end.