Why does my method of using combinations not work for this counting so program?

27 Views Asked by At

This is my solution for a computing contest, question S3 from 2017. Attached below is a link to the website with the question, and also an image of the question. It seems like I'm not accounting for certain combinations that extend the length of the board. Can someone help?

https://dmoj.ca/problem/ccc17s3 question

from itertools import combinations

num_pieces = int(input())
pieces = input()
pieces_list = list(combinations([int(num) for num in pieces.split()], 2))
possible_heights = [0]*4000
for item in pieces_list:
    possible_heights[item[0]+item[1]-1] += 1

print(max(possible_heights), possible_heights.count(max(possible_heights)))

I iterate through all possible combinations of board lengths, find out the heights that they create and add them to a list whose' index is the height of the board. The highest value of the list should be the maximum length possible, and the number of times it occurs is the second value of the output.

0

There are 0 best solutions below