Dawid and Bags of Candies

Dawid has four bags of candies. The ii-th of them contains aiai candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of candies in total?

Note, that you can’t keep bags for yourself or throw them away, each bag should be given to one of the friends.

Input

The only line contains four integers a1a1, a2a2, a3a3 and a4a4 (1≤ai≤1001≤ai≤100) — the numbers of candies in each bag.

Output

Output YES if it’s possible to give the bags to Dawid’s friends so that both friends receive the same amount of candies, or NO otherwise. Each character can be printed in any case (either uppercase or lowercase).

Sample Input

1 7 11 5
7 3 2 5

Sample Output

YES
NO

Note

In the first sample test, Dawid can give the first and the third bag to the first friend, and the second and the fourth bag to the second friend. This way, each friend will receive 1212 candies.

In the second sample test, it’s impossible to distribute the bags.

题目大意:

有四袋糖果,两个朋友。把每个包都给两个朋友中的一个,如果每个朋友收到相同数量的糖果输出YES否则输出NO,且不能为自己保留或扔掉袋子,每个袋子应该给一个朋友。

解题思路:

四袋糖果均分,两两相同;或者不均分,但每两袋总和相同。

代码如下:
#include<stdio.h>
int main(){
	int i,j,a[4],sum=0;
    scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3]);
    for(i=0;i<4;i++){
        sum+=a[i];//糖果总数
    }
    bool flag=false;
for(i=0;i<4;i++)
    if(a[i]*2==sum)//均分且分到的糖果数相等
    flag=true;
for(i=0;i<4;i++){
    for(j=i+1;j<4;j++)
        if((a[i]+a[j])*2==sum)//不均分但分到的糖果数也相等
        flag=true;
}
if(flag)
    printf("YES\n");
else
    printf("NO\n");
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值