Codeforces contest problem

the problem-https://codeforces.com/contest/1516/problem/A

Please tell me where I have gone wrong how to modify the code??

hello @Somasree
check now->

the output for all the test cases are coming correct but in this code
but it s comming like
Output
[2, 1, 5]
[0, 1]
but expected output is
2 1 5
0 1

I dont know why its happening

check now->

use print(*a) to remove brackets

ok.thank u so much :smiley:

its giving a wrong ans on test 2
please have a look
https://codeforces.com/contest/1516/submission/113853209

it was becuase of overflow.

check this. subtract till a[i] >0

for t in range(int(input())):
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    
    for i in range(n-1):#second element is already fixed which is a[n-1]. so we need to iterate till [n-2]
        while(k!=0 and a[i]>0):
            k=k-1
            a[i]=a[i]-1 #updated a[i]
            a[-1]=a[-1]+1
    print(*a)

its accepted thanku :smiley:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.