第二题100%,分别a, b排序,双指针 import sys n = int(sys.stdin.readline().strip()) nums = list() for i in range(n): a, b = map(int, sys.stdin.readline().strip().split()) nums.append([a, b, i]) nums_a = sorted(nums, key=lambda x:x[0], reverse=True) nums_b = sorted(nums, key=lambda x:x[1], reverse=True) posa = 0 posb = 0 res = 0 while(posa < n and posb < n): pre_a = nums_a[posa] pre_b = nums_b[posb] if pre_a[2] == pre_b[2]: posa += 1 continue val_a = pre_a[0]+pre_b[0] val_b = pre_a[1]+pre_b[1] val = min(val_a, val_b) res = max(res, val) if (val_a > val_b): posa += 1 else: posb += 1 print (res/2)
3 9

相关推荐

牛客网
牛客企业服务