forked from nathan-abela/HackerRank-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02 - Mark and Toys.py
More file actions
40 lines (30 loc) · 820 Bytes
/
02 - Mark and Toys.py
File metadata and controls
40 lines (30 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# ========================
# Information
# ========================
# Direct Link: https://www.hackerrank.com/challenges/mark-and-toys/problem
# Difficulty: Easy
# Max Score: 35
# Language: Python
# ========================
# Solution
# ========================
import os
# Complete the maximumToys function below.
def maximumToys(prices, k):
cost = 0
toys = 0
prices.sort()
for j in range(0, n-1):
if cost + prices[j] < k:
cost += prices[j]
toys += 1
return toys
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
nk = input().split()
n = int(nk[0])
k = int(nk[1])
PRICES = list(map(int, input().rstrip().split()))
RESULT = maximumToys(PRICES, k)
fptr.write(str(RESULT) + '\n')
fptr.close()