Don't see why wrong

I was doing problem USACO 2023 Bronze OPEN P1 and the program I made was wrong but I can’t see why(python). The 1st case works but the 2nd and 3rd don’t and say “x”. Here’s my code.

N = int(input())
costs = list(input().split())
costs.sort(reverse = True)
costs = [int(i) for i in costs]
money = 1
k = 1
highest_money = [0, 0]
while money != 0:
    money = 0
    for h in range(N):
        if costs[h] >= k:
            money += k
    if money > highest_money[0]:
        highest_money[0] = money
        highest_money[1] = k
    k += 1
print(highest_money[0], highest_money[1])


Yes, I have tried some test cases that work like a slightly simplified version of the test cases that don’t work and the answer matches with the answer given my the official solution so I’m not sure what’s wrong.