#include
print("请输入载重量c及古董个数n:")c=float(input())n=int(input())weight=[]print("请输入每个古董的重量:")for i in range(n): a=float(input("该古董重量:")) weight.append(a)for i in range(n): print(weight[i])weight.sort()print("古董重量升序排序后的结果:")for i in range(n): print(weight[i])ans=0#已装入的古董个数tmp=0.0#已装入的古董重量for i in range(n): tmp += weight[i] if tmp<=c: ans=ans+1 else:breaktmp=tmp-weight[-1]print("根据贪心策略能装入古董最大数量为ans=",ans)print("根据贪心策略能装入古董最大重量为tmp=",tmp)