首页 > 解决方案 > 代码厨师 | 卧推问题 - 我用示例测试用例解决了这个问题并部分解决了它。你能指出我错过了什么吗

问题描述

问题描述

输入和测试用例

Python3 代码:

testCases = int(input())
for i in range(testCases):
    line1 = [int(x) for x in input().split()]
    weights = [int(y) for y in input().split()]
    numberOfWeights,requiredWeight,rodWeight = line1[0],line1[1],line1[2]
    if (requiredWeight <= rodWeight):
        print("YES")
        continue
    lookupWeights = list()
    for j in range(numberOfWeights):
        if (requiredWeight <= rodWeight):
            break
        if(weights[j] in  lookupWeights):
            rodWeight += (2*weights[j])
            lookupWeights.remove(weights[j])
        else:
            lookupWeights.append(weights[j])
    if (requiredWeight <= rodWeight):
        print("YES")
    else:
        print("NO")

我已经尝试了很多测试用例,它似乎仍然可以正常工作,但没有被接受提交。现在我知道代码效率不高。我所需要的只是一个示例测试用例来破坏此代码/逻辑。

示例测试用例 1:

3
2 5 10 
2 2
7 100 50
100 10 10 10 10 10 90 
6 100 40 
10 10 10 10 10 10

Output: 
YES
NO
YES

TEST CASE 2:

1
8 100 40
10 20 10 25 30 40 30 50

Output:
YES

标签: pythontesting

解决方案


推荐阅读