题解 | #数组分组#

数组分组

https://www.nowcoder.com/practice/9af744a3517440508dbeb297020aca86

m = int(input())
o = list(map(int, input().split()))
five = []
three = []
other = []
for x in o:
    if x % 5 == 0:
        five.append(x)
    elif x % 3 == 0:
        three.append(x)
    else:
        other.append(x)

num1 = abs(sum(five) - sum(three))
num2 = sum(other)
num3 = num1 + num2
if num3 % 2 == 0:
    num4 = num3 // 2
    b = {0}
    for x in other:
        b = b | set(y+x for y in b)
    if num4 in b:
        print('true')
    else:
        print('false')
else:
    print('false')

全部评论

相关推荐

点赞 评论 收藏
分享
有工作后先养猫:太好了,是超时空战警,我们有救了😋
点赞 评论 收藏
分享
点赞 1 评论
分享
牛客网
牛客企业服务