代码改变世界

[编程题]糕点

2021-04-26 21:04  jetwill  阅读(270)  评论(0编辑  收藏  举报

小团的蛋糕铺长期霸占着美团APP中“蛋糕奶茶”栏目的首位,因此总会吸引各路食客前来探店。

小团一天最多可以烤n个蛋糕,每个蛋糕有一个正整数的重量。

早上,糕点铺已经做好了m个蛋糕。

现在,有一个顾客要来买两个蛋糕,他希望买这一天糕点铺烤好的最重的和最轻的蛋糕,并且希望这两个蛋糕的重量恰好为a和b。剩余的n-m个蛋糕可以现烤,请问小团能否满足他的要求?

输入描述:
输入包含多组数据,每组数据两行。

每组数据的第一行包含4个整数,n,m,a,b,空格隔开。这里不保证a和b的大小关系。

接下来一行m个数,空格隔开,代表烤好的蛋糕重量

输出描述:
对于每一组数据,如果可以办到顾客的要求,输出YES,否则输出NO

输入例子1:
4 2 2 4
3 3
4 2 2 4
1 1
4 2 2 4
5 5
4 2 4 2
2 4
2 2 2 4
3 3
3 2 2 4
3 3
3 2 2 4
3 3

输出例子1:
YES
NO
NO
YES
NO
NO
NO

result_lis=[]
while(True):
    try:
        n,m,a,b=map(int,input().split())
        temp_lis=[a,b]
        m_lis=list(map(int,input().split()))
        if a in m_lis and b in m_lis:
            result_lis.append("YES")
            #print("YES")

        elif max(m_lis)>max(temp_lis) or min(m_lis)<min(temp_lis):
            result_lis.append("NO")
            #print("NO")

        elif a in m_lis and b not in m_lis and n-m>=1:
            result_lis.append("YES")
            #print("YES")

        elif a not in m_lis and b in m_lis and n-m>=1:
            result_lis.append("YES")
            #print("YES")

        elif a not in m_lis and b not in m_lis and n-m>=2:
            result_lis.append("YES")
            #print("YES")

        else:
            result_lis.append("NO")
            #print("NO")
    except Exception as e:
            break
for _ in result_lis:
    print(_)