【Codeforces】1230A – Dawid and Bags of Candies

正文索引 [隐藏]

Problem Description:

Dawid has four bags of candies. The i-th of them contains a_{i} 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 Specification:

The only line contains four integers a_{1}, a_{2}, a_{3} and a_{4} (1≤a_{i}≤100) — the numbers of candies in each bag.

Output Specification:

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 Input1:

1 7 11 5

Sample Output1:


Sample Input2:

7 3 2 5

Sample Output2:



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 12 candies.
In the second sample test, it’s impossible to distribute the bags.




#include <bits/stdc++.h>
using namespace std;
#define Up(i,a,b) for(int i = a; i <= b; i++)
int main()
    cin.tie(0), cout.tie(0);
    int a[5];
        cin >> a[i];
    if(a[1]+a[4]==a[2]+a[3] || a[1]+a[2]+a[3]==a[4])
        cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;