小米 0902 开发笔试
打卡题a了,tm不支持go
老年人艰难上手python
import math n = int(input().strip().split(" ")[0]) datastr = input().strip() diff = math.inf res = 0 for i in datastr.split(","): cur1, cur2 = map(int, i.split(":")) if abs(cur1 - n) < diff: diff = abs(cur1 - n) res = cur2 elif abs(cur1 - n) == diff: res = (res + cur2) / 2.0 print("%.1f" % res)
n = input().strip().split(",") data = [] for i in n: cur1, cur2 = map(int, i.split(":")) data.append([cur1, cur2]) data.sort(key=lambda x: (x[0] - x[1], x[1], -x[0])) res = max(data[0]) temp = data[0][0] for i in range(1, len(data)): if data[i][1] > data[i][0]: if data[i][1] - data[i][0] >= res: res = data[i][1] continue if data[i][1] - data[i][0] < res: diff = res - data[i][1] + data[i][0] res = data[i][1] + diff # res += diff continue else: res = res + data[i][0] if res >= 4800: print(-1) else: if res < sum([data[i][0] for i in range(len(data))]): print(sum([data[i][0] for i in range(len(data))])) else: print(res)