#34972: python AC


1554101-0@g.puiching.edu.mo (P5A29)

學校 : 澳門培正中學
編號 : 216811
來源 : [202.86.172.162]
最後登入時間 :
2023-10-16 13:14:52
b159. NOIP2007 2.纪念品分组 -- NOIP2007普及組 | From: [27.109.151.69] | 發表日期 : 2023-04-30 15:18

w = int(input())
n = int(input())
prices = [0] + [int(input()) for _ in range(n)]
prices.sort()

left, right = 1, n
cnt = 0

while left <= right:
    if prices[left] + prices[right] <= w:
        left += 1
        right -= 1
    else:
        right -= 1
    cnt += 1

print(cnt)
 
ZeroJudge Forum