比赛 20120704 评测结果 AAAAAAAWWWW
题目名称 子集 最终得分 63
用户昵称 czp 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2012-07-04 11:19:42
显示代码纯文本
var
 x,y,f:array[1..200000] of longint;
 w:array[1..10000] of longint;
 o:array[1..10000] of boolean;
 i,j,m,n,xx,yy,mid,tp,dns,ans,v,de,lv,ll,l,dans,sm,tv:longint;
 procedure sort(l,r:longint);
 var i,j:longint;
 begin
  i:=l;
  j:=r;
  mid:=x[(l+r) div 2];
  repeat
  while x[i]<mid do inc(i);
  while x[j]>mid do dec(j);
  if i<=j then
   begin
    tp:=x[i];x[i]:=x[j];x[j]:=tp;
    tp:=y[i];y[i]:=y[j];y[j]:=tp;
    inc(i);dec(j);
   end;
  until i>j;
  if i<r then sort(i,r);
  if j>l then sort(l,j);
 end;
begin
 assign(input,'subseta.in');reset(input);
 assign(output,'subseta.out');rewrite(output);
 readln(n);
 randomize;
 for i:=1 to n do
  read(w[i]);
 readln;
 readln(m);
 j:=0;
 for i:=1 to m do
  begin
   readln(xx,yy);
   inc(j);
   x[j]:=xx;y[j]:=yy;
   inc(j);
   x[j]:=yy;y[j]:=xx;
  end;
 sort(1,2*m);
 for i:=2*m downto 1 do
  f[x[i]]:=i;
 f[x[2*m]+1]:=2*m+1;
 lv:=1; dans:=0;
 repeat
  inc(lv);
  j:=random(n)+1;
  inc(sm);
  if not o[j] then
   begin
    de:=w[j];
    for l:=f[j] to f[j+1]-1 do
     if o[y[l]] then  de:=de-w[y[l]];
    if de>=0 then
     begin
      o[j]:=true;
      for l:=f[j] to f[j+1]-1 do
       o[y[l]]:=false;
      dans:=dans+de;
     if dans>ans then begin ans:=dans;sm:=0; end;
    end;
   end;
  if sm>100 then begin
   for tv:=1 to 10 do begin
    j:=random(n)+1;
    if not o[j] then
    begin
    de:=w[j];
    for l:=f[j] to f[j+1]-1 do
     if o[y[l]] then  de:=de-w[y[l]];
      o[j]:=true;
      for l:=f[j] to f[j+1]-1 do
       o[y[l]]:=false;
      dans:=dans+de;
     if dans>ans then begin ans:=dans;sm:=0; end;
    end;
    end;
    end;
 until lv>60000;
 writeln(ans);
 close(input);close(output);
end.