PROBLEM LINK:
Practice
Contest Link
Problem Link
Author: Akash Kumar Bhagat
Tester: Anjali Jha
Editorialist: Karan Ghorai
DIFFICULTY:
Easy
PROBLEM:
Problem comes down to checking whether the given array can be divided into two subarrays have equal sum.
QUICK EXPLANATION:
Need to check if the target is achievable by prefix or suffix sum maintaining the edge cases.
EXPLANATION:
After creating a fresh array of elements consisting of only valid elements, need to check if the target sum is achievable by prefix or suffix sum maintaining the edge cases.
TIME COMPLEXITY:
O(N), where N is the size of the given array.
SOLUTIONS:
Editorialist's Solution
for _ in range(int(input())):
n,x = map(int,input().split())
a = [int(i) for i in input().split()]
target = (sum(a) - x*a.count(x))
target /= 2
chk = 0
for i in a:
if i == x: continue
chk += i
if chk >= target:
break
ans = "WAR" if chk > target else "PEACE"
print(ans)