比赛 2008haoi模拟训练1 评测结果 WWWWWWWWEE
题目名称 最大获利 最终得分 0
用户昵称 cuixiaofei 运行时间 0.401 s
代码语言 Pascal 内存使用 61.74 MiB
提交时间 2008-04-22 11:24:18
显示代码纯文本
//na                            :cuixiaofei;
//da                            :08_04_22;
program profit;
  const
    max                         =4000{4000};
  var
    n,m,ge,he,fei               :longint;
    a                           :array[1..max,1..max] of longint;
    b                           :array[1..max] of longint;
    pc                          :array[1..max*10] of boolean;
    c                           :array[1..max*10,1..3] of longint;
    f1,f2                       :text;
  procedure init;
    var
      i,a1,a2                   :longint;
  begin
    assign(f1,'profit.in');
    reset(f1);
    assign(f2,'profit.out');
    rewrite(f2);
    fillchar(a,sizeof(a),0);
    he:=0;
    fei:=0;
    readln(f1,n,m);
    ge:=0;
    for i:=1 to n do
      read(f1,b[i]);
    for i:=1 to m do
      begin
        readln(f1,a1,a2,a[a1,a2]);
        a[a2,a1]:=a[a1,a2];
        if b[a1]+b[a2]<=a[a1,a2]*2 then
          begin
            inc(ge);
            c[ge,1]:=a1;
            c[ge,2]:=a2;
            c[ge,3]:=a[a1,a2];
          end;
      end;
  end;
  procedure chengxing;
    var
      i,j                       :longint;
  begin
    fillchar(pc,sizeof(pc),false);
    for i:=1 to ge do
      begin
        if pc[c[i,1]]=false then
          begin
            fei:=fei+b[c[i,1]];
            pc[c[i,1]]:=true;
          end;
        if pc[c[i,2]]=false then
          begin
            fei:=fei+b[c[i,2]];
            pc[c[i,2]]:=true;
          end;
      end;
    for i:=1 to ge do
      he:=he+c[i,3];
  end;
  procedure qubian;
    var
      xiaofei,xiaohe,i,j         :longint;
  begin
    for i:=1 to ge do
      begin
        xiaofei:=0;
        xiaohe:=0;
        for j:=1 to n do
          if pc[j]=true then
          begin
            if (a[c[i,1],j]<>0) then
              xiaohe:=xiaohe+a[c[i,1],j];
            if (a[c[i,2],j]<>0) then
              xiaohe:=xiaohe+a[c[i,2],j];
          end;
        xiaohe:=xiaohe-c[i,3];
        xiaofei:=xiaofei+b[c[i,1]];
        xiaofei:=xiaofei+b[c[i,2]];
        if xiaofei>xiaohe then
          begin
            he:=he-xiaohe;
            fei:=fei-xiaofei;
          end;
      end;
  end;
  procedure main;
    var
      i,j                       :longint;
  begin
    chengxing;
    qubian;
    writeln(f2,he-fei);
    close(f1);
    close(f2);
  end;
  begin
    init;
    main;
  end.