#K2396. Balanced Card Deck
Balanced Card Deck
Balanced Card Deck
A deck of cards consisting of \(2N\) cards is called balanced if the sum of the values of its first \(N\) cards is equal to the sum of the values of its last \(N\) cards. In this problem, you are given multiple decks and you need to determine whether each deck is balanced.
More formally, let the deck be represented as a sequence \(a_1, a_2, \ldots, a_{2N}\). The deck is balanced if and only if \[ \sum_{i=1}^{N} a_i = \sum_{i=N+1}^{2N} a_i. \]
You need to process each test case and output YES
if the deck is balanced or NO
otherwise.
inputFormat
The input is given via standard input and consists of multiple test cases. The first line contains an integer \(T\) denoting the number of test cases. For each test case:
- The first line contains an integer \(N\), representing half the number of cards.
- The second line contains \(2N\) space-separated integers representing the values of the cards in order.
It is guaranteed that each deck has exactly \(2N\) cards.
outputFormat
For each test case, print a single line containing YES
if the corresponding deck is balanced, or NO
otherwise.
2
1 3 2 2
YES
</p>