题解 | #牛牛的数组匹配#
牛牛的数组匹配
http://www.nowcoder.com/practice/3d3406f4a7eb4346b025cc592be5b875
没人写双百分百doge
import sys
n = [i.strip().split(' ') for i in sys.stdin.readlines()]
sz = list(map(int, n[0]))
a = list(map(int, n[1]))
b = list(map(int, n[2]))
sum_a = sum(a)
distance = {}
distance_array=[]
for i in range(1, len(b)+1):
for j in range(0, len(b)-i+1):
d = abs(sum(b[j:j+i])-sum_a)
if str(d) not in distance:
distance[str(d)] = [j, j+i]
distance_array.append(d)
dd = min(distance_array)
ind = distance[str(dd)]
print(''.join(str(i)+' ' for i in b[ind[0]:ind[1]]))