There are n contract values. Every contract must be assigned to exactly one of two teams (a team may end up with none of the contracts). Determine whether an assignment exists in which both teams' contracts sum to the SAME total.
Line 1: an integer n.
Line 2: n space-separated non-negative integers, the contract values (empty if n = 0).
Print YES if the contracts can be split into two equal-sum groups, otherwise print NO.
Example 1
Input
4 1 5 11 5
Expected
YES
Explanation
The total is 22; the single contract worth 11 forms one team and the rest (1+5+5=11) forms the other: YES.
Example 2
Input
3 1 2 4
Expected
NO
Explanation
The total is 7, which is odd, so an equal split is impossible: NO.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →