A. Dawid and Bags of Candies time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output 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). Examples input Copy 1 7 11 5 output Copy YES input Copy 7 3 2 5 output Copy 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.
|
#include <iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn=1010;
int a[maxn];
int main()
{
int n=4;
for(int i=0; i<n; i++)
{
cin>>a[i];
}
sort(a,a+n);
int sum,ans;
sum=ans=0;
ans=a[3];
int l=0;
n=2;
while(n>=0)
{
if(ans>sum)
sum+=a[n--];
else
{
ans+=a[n--];
}
}
//printf("%d %d\n",sum,ans);
if(ans==sum)
cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}