E题超时,求大佬指点。请问这样做复杂度是O(q n2)吗?

我是用前缀和先处理了一下A数组,然后对b数组的每个依次入堆,ans[i]存要i个b任务的最小时间,然后更新ans数组的值,能过83%,求大佬指点

import heapq

n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [float('inf')] * (n + 2)
sa = [0] * (n + 2)
sa[0] = a[0]
q = []
for i in range(1, n):
    sa[i] = sa[i - 1] + a[i]
for i in range(0, n):
    nt = sa[i]
    heapq.heappush(q, b[i])
    res = 1
    for j in heapq.nsmallest(i+1,q):
        nt += j
        ans[res] = min(ans[res], nt)
        res += 1
for i in range(m):
    t = int(input())
    print(ans[t])

全部评论

相关推荐

不愿透露姓名的神秘牛友
08-11 17:58
怎么感觉全世界都转码了
蜻蜓队长:其实很多转码的人本身是非常适合学计算机的,只是自己当年没选对专业😂
点赞 评论 收藏
分享
嗨害嗨我来了:你跟他说开迈巴赫呢,一个月好几万,让学弟尝尝一点小小的社会险恶
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 17:35
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务