贝壳笔试9.7,第三题单纯读取输入就超时
数据挖掘机器学习方向笔试第三题,用Python读取输入直接超时,啥玩意,垃圾题目浪费时间,反馈还反馈半小时
#笔试题目##贝壳找房#
最后附上自己的答案
import sys def solution(price, money): price.sort(key=lambda x: [x[1], -x[0]]) money.sort(key=lambda x: x[1]) res = [] n, m = len(price), len(money) i, j = 0, 0 while i < n and j < m: if i == n&nbs***bsp;money[j][1] < price[i][1]: if i > 0: res.append([price[i - 1][0], price[i - 1][1], money[j][0]]) else: res.append([-1, -1, money[j][0]]) j += 1 else: if i < n: i += 1 res.sort(key=lambda x: x[2]) return res T = int(input()) for _ in range(T): n = int(input()) temp = list(map(int, sys.stdin.readline().strip().split())) price, money = [], [] for i in range(n): price.append([i + 1, temp[i]]) q = int(input()) for i in range(q): x, y, z = list(map(int, sys.stdin.readline().strip().split())) temp = x * y * z money.append([i + 1, temp]) res = solution(price, money) for i in range(len(res)): if res[i][0] == -1: print(-1) else: print(res[i][0], res[i][1])
补一个单纯读取输入就超时的图片