Search for a command to run...
Progressive hints first, then the full explanation and implementation when you're ready to cash out.
Review status
AI-generated and still unreviewed. Double-check the details before internalizing them.
Hints
Open only as much as you need to keep the solve alive.
Ask what parity the sum of two even numbers must have.
Two even parts always have an even total, so every odd value of is impossible.
Being even is not quite sufficient: both parts must have positive even weight, and the smallest positive even weight is .
Therefore the total must be even and at least .
The complete condition is w % 2 == 0 && w > 2. For every such , the split proves that the answer is YES.
The whole problem comes down to parity plus one annoying edge case.
Suppose the two part weights are and . We need
where both and are positive even integers.
The sum of two even integers is even. Therefore, if is odd, no valid split can exist.
That does not mean every even works. The smallest positive even integer is , so both boys receiving a positive even part requires
This rules out . That is the only trap here: splitting it as has even weights, but zero is not positive, so Pete or Billy gets existential disappointment instead of watermelon.
Now suppose is even and . Since integer weights are used, this means . Choose the parts
The first part is positive and even. Because and are even, is also even; and because , it is positive. Thus this split is always valid.
So the exact answer is:
YES when is even and greater than ;NO.If the algorithm prints YES, then and is even. The split consists of two positive even integers, so a valid division exists.
If a valid division exists, both parts are positive even integers. Their sum must therefore be even, and each part is at least , giving , hence . Therefore the algorithm prints YES.
The algorithm prints YES exactly when a valid division exists.
The algorithm uses time and extra space.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int w;
cin >> w;
cout << (w > 2 && w % 2 == 0 ? "YES" : "NO") << '\n';
}#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int w;
cin >> w;
cout << (w > 2 && w % 2 == 0 ? "YES" : "NO") << '\n';
}