比赛 |
2008haoi模拟训练1 |
评测结果 |
WWWWWWWWEE |
题目名称 |
最大获利 |
最终得分 |
0 |
用户昵称 |
梦里醉逍遥 |
运行时间 |
0.818 s |
代码语言 |
Pascal |
内存使用 |
7.83 MiB |
提交时间 |
2008-04-22 10:52:50 |
显示代码纯文本
program profit;
const
fi='profit.in'; fo='profit.out'; maxn=1000;
type
arr1=array[1..maxn] of longint;
arr2=array[1..maxn,1..maxn] of longint;
var
fin,fout:text;
n,m,max:longint;
v,s:arr1; d,t:arr2;
procedure init;
var
i,j,k,l:longint;
begin
assign(fin,fi); reset(fin);
readln(fin,n,m);
for i:=1 to n do begin
read(fin,v[i]);
s[i]:=i; v[i]:=-v[i];
end;
for i:=1 to m do begin
readln(fin,j,k,l);
d[j,k]:=l; d[k,j]:=l;
end;
close(fin);
end;
procedure main;
var
i,j,k,l,best,besti,bestj:longint;
begin
for i:=1 to n do
for j:=1 to n do
t[i,j]:=d[i,j];
max:=-maxlongint;
for l:=1 to n-1 do begin
best:=-maxlongint;
for i:=1 to n do
for j:=1 to n do
if (s[i]<>s[j]) and (t[i,j]>0) then
if v[i]+v[j]+t[i,j]>best then begin
best:=v[i]+v[j]+t[i,j];
besti:=i; bestj:=j;
end;
if best>max then max:=best;
k:=s[bestj];
for i:=1 to n do begin
if s[i]=k then s[i]:=s[besti];
if s[i]=s[besti] then v[i]:=best;
end;
for j:=1 to n do begin
k:=0;
for i:=1 to n do
if s[i]=s[besti] then k:=k+d[i,j];
for i:=1 to n do
if s[i]=s[besti] then t[i,j]:=k;
end;
end;
end;
procedure print;
begin
if max<0 then max:=0;
assign(fout,fo); rewrite(fout);
writeln(fout,max); close(fout);
end;
begin
init;
main;
print;
end.