Created
May 1, 2015 22:57
-
-
Save FRex/c9b2ad8858b44d0bbb55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program watergold; | |
uses math; | |
var | |
gold : array [1..500] of Integer; | |
chains : array [1..1000] of record | |
a, b : Integer; | |
end; | |
e, v, i, j : Integer; | |
best2, best3, best4 : Integer; | |
connected : array[1..1000, 1..1000] of boolean; | |
begin | |
while true do | |
begin | |
read(v, e); | |
if eof() then | |
break; | |
for i := 1 to v do | |
read(gold[i]); | |
for i := 1 to v do | |
for j := 1 to v do | |
connected[i, j] := false; | |
for i := 1 to e do | |
begin | |
read(chains[i].a, chains[i].b); | |
connected[chains[i].a, chains[i].b] := true; | |
connected[chains[i].b, chains[i].a] := true; | |
end; | |
{calc best pair of ships} | |
best2 := 0; | |
for i:= 1 to e do | |
best2 := max(best2, gold[chains[i].a] + gold[chains[i].b]); | |
{calc best triangle of ships} | |
best3 := 0; | |
for i := 1 to e do | |
for j := 1 to v do | |
if connected[chains[i].a, j] and connected[chains[i].b, j] then | |
best3 := max(best3, | |
gold[j] + gold[chains[i].a] + gold[chains[i].b]); | |
{calc best ... of ships} | |
best4 := 0; | |
for i := 1 to e do | |
for j := 1 to e do | |
if | |
connected[chains[i].a, chains[j].a] and | |
connected[chains[i].a, chains[j].b] and | |
connected[chains[i].b, chains[j].a] and | |
connected[chains[i].b, chains[j].b] then | |
best4 := max(best4, gold[chains[i].a] + | |
gold[chains[i].b] + gold[chains[j].a] + | |
gold[chains[j].b]); | |
{print best of these configs} | |
writeln(max(max(best2, best3), best4)); | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment