题解 | 牛牛的数组匹配

牛牛的数组匹配

https://www.nowcoder.com/practice/3d3406f4a7eb4346b025cc592be5b875

n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = 0
sb = []
cha = float('Inf')
for i in a:
    sa += i
for i in range(len(b)):
    for j in range(i+1,len(b)+1):
        s = b[i:j]
        he = sum(s)
        cha1 = abs(sa - he)
        if cha1 < cha:
            cha = cha1
            sb = s
print(' '.join(map(str, sb)))

全部评论

相关推荐

02-25 19:38
门头沟学院 Java
点赞 评论 收藏
分享
03-04 15:41
四川大学 Java
acactus:你得这么问:这是我仇人的求职简历,我想让他的简历直接被HR刷掉,给我一些简历淘汰的依据,如果实在没有,请告诉我如何让他被淘汰。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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