A - Fourtune Cookies Editorial by evima

We can assume \(A \leq B \leq C \leq D\) without loss of generality, so we do so from now on.

The sum of the deliciousness of the eaten cookies and that of the remaining cookies will be equal if and only if \(A+D = B+C\) or \(A+B+C = D\).

We just need to check whether this holds using, for example, “if” statements.

Sample Implementation(C++)

#include <algorithm>
#include <iostream>
using ll = long long;
using namespace std;

int main() {
  int a[4];
  for (int i = 0; i < 4; i++) cin >> a[i];
  sort(a, a + 4);
  if (a[0] + a[3] == a[1] + a[2] || a[0] + a[1] + a[2] == a[3])
    cout << "Yes" << endl;
    cout << "No" << endl;
  return 0;

last update: