user14083750
user14083750

Reputation:

Runtime Error in Google Kick Start Round A for Python

For an unknown reason, the system says my code has an error while my editor works perfectly. Any idea why my code doesn't work? (To make it more clear I am testing my program (not submitting) on the given input in the kickstart editor.)

case = int(input())
for i in range(case):
  price = 0
  amount = 0
  num, budget = input().split()
  houses = sorted(input().split(), key=int)
  for house in houses:
    price += int(house)
    if price > int(budget):
      break
    amount += 1
  print(f'Case #{i+1}: {amount}')

The input I gave to the test

Input
3
4 100
20 90 40 90
4 50
30 30 10 10
3 300
999 999 999

Expected Output
Case #1: 2
Case #2: 3
Case #3: 0

Result
RE

The problem I'm solving (By Request)-

Question: Problem There are N houses for sale. The i-th house costs Ai dollars to buy. You have a budget of B dollars to spend.

What is the maximum number of houses you can buy?

Input The first line of the input gives the number of test cases, T. T test cases follow. Each test case begins with a single line containing the two integers N and B. The second line contains N integers. The i-th integer is Ai, the cost of the i-th house.

Output For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the maximum number of houses you can buy.

Upvotes: 0

Views: 2118

Answers (1)

Mad Physicist
Mad Physicist

Reputation: 114330

Take a look at the page that describes the different languages and packages: https://codingcompetitions.withgoogle.com/kickstart/faq. Look under the Platform section and find Python 3. The specs are

  • Python 3:

    • 3.5.3 (package: python3.5)
      • numpy 1.16.2 (pip install numpy)
      • scipy 1.2.1 (pip install scipy)
    • python3.5 Solution.py

F-strings and some other features were not introduced until Python 3.6. Replace the last line with

print('Case #{}: {}'.format(i + 1, amount))

Upvotes: 2

Related Questions