Editorial for Another Contest 5 Problem 1 - Goat Fence

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.

With the bounds as low as they are, several different solutions were possible. One approach is to brute force over all pairs of side lengths l and w where 1 \le l, w \le N and list out the rectangle with the maximum perimeter - with N \le 100, this solution comfortably runs in time.

It follows fairly directly from the problem statement that the maximum perimeter is at least 2N+2 - a rectangle with dimensions 1 \times N clearly attains this perimeter. We actually cannot do better than this. Therefore, it suffices to read in N and print 2N + 2.


There are no comments at the moment.