第四题

6 views
Skip to first unread message

王希元

unread,
Jan 2, 2019, 5:14:47 AM1/2/19
to cs10...@googlegroups.com
p=int(input())
a=[int(i)for i in input().split()]
a.sort()
x=0
i=0
t=len(a)
while i<t:
   
    if p>=a[i]:
        x+=1
        p-=a[i]
        i+=1
    else:
        if x>0 and t>i+1:
            x-=1
            p+=a[t-1]
            t-=1
        else:
            break
print(x
Reply all
Reply to author
Forward
0 new messages