HUAWEI 机试题:参赛团队能力值 (Python解法)

https://blog.csdn.net/weixin_47243236/article/details/123056359?spm=1001.2014.3001.5502

Python解法

N = int(input())
abi = sorted(list(map(int, input().split(' '))))
t = int(input())
flags = [-1 for _ in range(N)]
res = 0

for i, right in enumerate(abi[::-1]):
    if right > t:
        res += 1
    else:
        for j, left in enumerate(abi[:N-1-i]):
            if flags[j] == 0:
                continue
            if right+left >= t:
                res += 1
                flags[j] = 0
                break
print(res)
                

你可能感兴趣的:(python,算法)