Explanation
We can divide the watermelon in half if and only if the weight is an even number and it's greater than 2.
Implementation
Time Complexity:
C++
#include <iostream>using namespace std;int main() {int w;cin >> w;if (w % 2 == 0 && w > 2) {cout << "YES" << endl;} else {cout << "NO" << endl;}}
Java
import java.io.*;import java.util.*;public class Watermelon {public static void main(String[] args) {Kattio io = new Kattio();int w = io.nextInt();if (w % 2 == 0 && w > 2) {io.println("YES");} else {
Python
w = int(input())if w % 2 == 0 and w > 2:print("YES")else:print("NO")
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!