下面的uva-11292代码有什么问题吗?显示超时限制错误

时间:2019-08-29 17:14:03

标签: python-3.7 uva

为什么我的代码显示“超过时限”错误?有没有相关的问题?我是否使用任何可能导致错误的内建函数?

while True:
    str_input = input()

    n = int(str_input.split()[0])
    m = int(str_input.split()[1])
    if n == 0 and m == 0:
        break

    if n > m:
        print("Loowater is doomed!")
        break

    head_diameter_list = []
    knights_height_list = []

    for i in range(n):
        head_diameter_list.append(int(input()))

    for i in range(m):
        knights_height_list.append(int(input()))

    head_diameter_list.sort()
    knights_height_list.sort()

    selected_knights_list = [0]
    for i in range(n):
        for j in range(m):
            if knights_height_list[j] >= head_diameter_list[i]:
                selected_knights_list.append(knights_height_list[j])
                break

    p = len(head_diameter_list)
    q = len(selected_knights_list)-1
    if p <= q:
        print(sum(selected_knights_list))
    else:
        print("Loowater is doomed!")

0 个答案:

没有答案