Editorial for COCI '11 Contest 6 #1 Jack


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.

N is small enough to try out all the possible combinations of three cards. There are less than 100^3 combinations. We can use three nested for-loops: first one to choose the first card we will take, second one to choose the second card, and third one to choose the final card.

In the inner loop, we check if the sum of the chosen cards is greater than M. If it is, we continue to the next combination. If it's not, we check if this sum is greater than the best sum found so far and update that sum if it is. At the end, we simply output the largest sum found.


Comments

There are no comments at the moment.