#K71682. Seesaw Balancing
Seesaw Balancing
Seesaw Balancing
A seesaw is considered balanced if and only if the moment on the left side equals the moment on the right side. For a seesaw with N positions, the left moment is calculated as follows:
\(\text{Left Moment}=\sum_{i=1}^{N} w_{L_i} \times i\)
and the right moment is computed as:
\(\text{Right Moment}=\sum_{i=1}^{N} w_{R_i} \times i\)
For each test case, if the left and right moments are equal, output YES
; otherwise, output NO
.
inputFormat
The first line contains an integer T representing the number of test cases. Each test case consists of three lines:
- An integer N denoting the number of positions on the seesaw.
- N space-separated integers representing the weights on the left side.
- N space-separated integers representing the weights on the right side.
outputFormat
For each test case, output a single line containing YES
if the seesaw is balanced, or NO
otherwise.
3
2
4 5
3 12
2
4 9
2 6
4
5 6 4 3
9 2 7 3
NO
NO
NO
</p>