文章
4
粉丝
169
获赞
3
访问
34.0k
while True: try: x, n = map(int, input().split()) dict = {} dict2 = {} if x == -1 and n == -1: pass else: for j in range(n): mi, wi = map(int, input().split()) danjia = wi / mi dict.setdefault(mi, danjia) dict2.setdefault(mi, wi) list1 = sorted(dict.items(), key=lambda x: (x[1], x[0])) total_mi = 0 # ml total_wi = 0 # money for i in range(len(list1)): if dict2[list1[i][0]] <= x: total_mi += list1[i][0] x -= dict2[list1[i][0]] else: total_mi += (list1[i][0]/dict2[list1[i][0]])*x break print('%.3f' % total_mi) except: break
登录后发布评论
暂无评论,来抢沙发