题解 | 牛牛的数组匹配

牛牛的数组匹配

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)))

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

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