#C5037. Rearranging Shelf Books
Rearranging Shelf Books
Rearranging Shelf Books
You are given a shelf with N books. Each book has a number representing the number of books at that position. Your goal is to determine if it is possible to rearrange these books such that the sum of the numbers at the odd positions is equal to the sum at the even positions.
This is equivalent to checking if the list of numbers can be partitioned into two groups with equal sum. Mathematically, if \( S \) is the total sum, then each group must sum up to \( \frac{S}{2} \). If \( S \) is odd, the answer is immediately "NO". Otherwise, you need to determine if a subset of the numbers sums up to \( \frac{S}{2} \).
Input Format: The first line contains an integer \( N \), the number of books. The second line contains \( N \) space-separated integers representing the numbers on each book.
Output Format: Output "YES" if it is possible to rearrange the books to satisfy the condition, otherwise output "NO".
inputFormat
The input is given via standard input with the following format:
- The first line contains a single integer \( N \) (the number of books).
- The second line contains \( N \) integers separated by spaces, where the \( i^{th} \) integer represents the number of books at the \( i^{th} \) position.
outputFormat
Output a single line to standard output: "YES" if it is possible to rearrange the books such that the sum of books in odd indexed positions equals the sum of books in even indexed positions; otherwise, output "NO".
## sample5
3 1 4 2 8
YES