#43694: 給自己的解題紀錄


suyueh (suyueh)

學校 : 不指定學校
編號 : 272111
來源 : [101.12.160.127]
最後登入時間 :
2024-11-21 22:51:47
c471. apcs 物品堆疊 (Stacking) -- apcs | From: [101.10.44.86] | 發表日期 : 2024-10-23 22:53

from functools import cmp_to_key while True: try: N = int(input().strip()) W = input().strip().split() F = input().strip().split() obj = [[int(w), int(f)] for w, f in zip(W, F)] obj.sort(key=cmp_to_key(lambda a, b: a[0]*b[1] - b[0]*a[1])) energy = 0 cum_w = 0 for i in range(N-1): cum_w += obj[i][0] energy += cum_w * obj[i+1][1] print(energy) except: break

 
ZeroJudge Forum