Editorial for Hearth
Submitting an official solution before solving the problem yourself is a bannable offence.
Since the bounds on ~N~ are so small, we can simply use 3 for loops to check all possible combinations, appending all valid ones into a list, and then sorting everything. This problem is similar to a past CCC question, The Students' Council Breakfast.
n,t = map(int,raw_input().split()) cards =  for i in range(n): name,cost = raw_input().split() cost = int(cost) cards.append([name,cost]) works =  for i in range(n-2): for j in range(i+1,n-1): for k in range(j+1,n): if cards[i]+cards[j]+cards[k] <= t: works.append(sorted([cards[i],cards[j],cards[k]])) works.sort() for i in works: print i,i,i