import sys def get_buyable(P, money): curmax = 0 curid = -1 for i in range(len(P)): if P[i] <= money: if P[i] > curmax: curmax = P[i] curid = i if curid == -1: return -1, -1 else: return curid, curmax n = int(sys.stdin.readline().strip()) values = [] for i in range(n): k = int(sys.stdin.readline().strip()) line = sys.stdin.readline().strip() P = list(map(int, line.split())) values.append(P) q = int(sys.stdin.readline().strip()) Q = [] for j in range(q): line = sys.stdin.readline().strip() x, y, z = list(map(int, line.split())) money = x * y * z curid, curmax = get_buyable(P, money) if curid == -1: print(-1) else: print(curid + 1, curmax) 我怀疑过价格是不是从小到大,可以二分查找,但我试了2分查找,也是超时好吧
点赞 2

相关推荐

不愿透露姓名的神秘牛友
08-15 16:48
想要一个AK:问题很多加微信私聊 (一个赞十道算法题,我看看有多少)
点赞 评论 收藏
分享
牛客网
牛客企业服务