Python · August 26, 2022 0

CCC ’17 S3 – Nailed It!

Nailed It! is a CCC senior 3/ junior 5 question. The method to solve this is similar to Escape Room. The first thing to do to solve this problem is to create a list that measures that number of boards that are length N into the term N. Then, we take another list that has all the possibilities. For every possibility term, we take all the possible combinations by using the previous list.

Take out the maximum value in the list of combinations. That would be the first part of the output. The second part is the number of times the max value appears in the list.

Example solution:

from math import floor
a = int(input())
wood = input().split()
for i in range(a):
    wood[i] = int(wood[i])
# The number of occurrences for every number
occurrences = [0 for i in range(2001)]
for i in wood:
    occurrences[i] += 1
# number of boards for every length
woods = [0 for i in range(4001)]
for p in range(1, 4001):
    for i in range(1, p//2+1):
        j = p-i
        if i > 2000 or j > 2000:
            continue
        if j == i:
            woods[p] += occurrences[i]//2
        elif occurrences[i] > 0 and occurrences[j] > 0:
            woods[p] += min(occurrences[i], occurrences[j])
a = max(woods)
total = 0
for i in woods:
    if i == a:
        total += 1
print(a, total)