EQUALDIST-Editorial

PROBLEM LINK:

Contest Division 1
Contest Division 2
Contest Division 3
Contest Division 4

Setter: Lavish Gupta
Tester: Nishank Suresh, Abhinav sharma
Editorialist: Devendra Singh

DIFFICULTY:

330

PREREQUISITES:

None

PROBLEM:

Alice and Bob are very good friends, and they always distribute all the eatables equally among themselves.

Alice has A chocolates, and Bob has B chocolates. Determine whether Alice and Bob can distribute all the chocolates equally among themselves.

Note that it is not allowed to break a chocolate into more than one piece.

EXPLANATION:

If A+B is even, both of them can have \frac{A+B}{2} chocolates otherwise both of them cannot have equal number of chocolates as the total number of chocolates is odd.

TIME COMPLEXITY:

O(1) for each test case.

SOLUTION:

Editorialist's Solution
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(), _obj.end()
#define F first
#define S second
#define pll pair<ll, ll>
#define vll vector<ll>
ll INF = 1e18;
const int N = 1e5 + 11, mod = 1e9 + 7;
ll max(ll a, ll b) { return ((a > b) ? a : b); }
ll min(ll a, ll b) { return ((a > b) ? b : a); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void sol(void)
{
    int a, b;
    cin >> a >> b;
    cout << (((a + b) % 2) ? "NO\n" : "YES\n");
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    int test = 1;
    cin >> test;
    while (test--)
        sol();
}

1 Like

i did like if(difference(a,b) % 2 == 0) then return YES, or else return NO,
And it worked, i really dont know how XD