My issue
I’m not getting, which testcase is getting failed… I think the programm is correct
My code
def generate_array(N, K):
if K % 2 != 0 and N!=2:
return [-1]
half_N = N // 2
if half_N * 2 > K:
return [-1]
arr = [1] * half_N + [2] * half_N # Create an alternating array of 1s and 2s
if K >max(arr):
last_element = K - sum(arr)+2 # Adjust the last element to meet the sum
arr[-1] = last_element
return arr
for i in range(int(input())):
N,K = map(int, input().split())
result = generate_array(N, K)
if result == [-1]:
print(-1)
else:
print(*result)
Problem Link: SUMARRAY Problem - CodeChef