#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the maximumToys function below.
def maximumToys(prices, k):
p=sorted(prices) ####直接用sorted(),如果用自己写的算法,runtime error
count=0
amount=0
for price in p:
amount+=price
if amount>k:
return count
else:
count+=1
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()
Sorting: Mark and Toys
猜你喜欢
转载自blog.csdn.net/weixin_45405128/article/details/104217838
今日推荐
周排行