Editorial for COCI '11 Contest 2 #1 Najboljih 5


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

It is possible to solve this task in various ways. Except for the most obvious solution where one looks for the 5 wanted numbers with 5 nested loops, we could just search for the 3 numbers with minimum sum and use 3 nested loops, which simplifies the code.

min=total; //sum of all numbers

for i=1 to 6 do
    for j=i+1 to 7 do
        for k=j+1 to 8 do
            if score[i]+score[j]+score[k] < min then
            begin
            min:=score[i]+score[j]+score[k];
            first:=i;
            second:=j;
            third:=k;
            end;

print (total-min);

for i=1 to 8 do
    if (i != first) and (i != second) and (i != third) then
        print (i);

Comments

There are no comments at the moment.