Codejam Qualification Round 2022. Task 2 Variant 2
Python Only
def gen_vector(v,s=10**6):
if sum(v) < s:
yield 'IMPOSSIBLE'
else:
for c in range(v[0],1,-1):
m=min([v[1],10**6-c])
y=min([v[2],10**6-c-m])
k=10**6-c-m-y
yield '%d %d %d %d'%(c,m,y,k)
T=int(input())
for t in range(T):
N=[]
for i in range(3):
N.append(list(map(int,input().split())))
v=[min([N[i][j] for i in range(3)])
for j in range(4)]
print('Case #%d: %s'%(t+1,next(gen_vector(v))))