My issue
i am finding a zero and then im doing it…1
5
1 11
1 2
1 3
1 2
0 4
for this my program is giving correct output 0 but expcetd output is something really wierd
My code
# cook your dish here
t=int(input())
for i in range(t):
n=int(input())
a=[]
b=[]
c=[]
for j in range(n):
x,y=map(int,input().split())
c.insert(j,j+1)
a.insert(j,x)
b.insert(j,y)
for j in range(n):
if a[j]==0:
k=j-1
while k>=0:
if a[k]==1:
if b[k]==b[j]:
a[k]=-1
a[j]=-1
elif b[k]>b[j]:
b[k]+=b[j]
a[j]=-1
else:
b[j]+=b[k]
a[k]=-1
k=k-1
flag=0
for j in range(n):
if a[j]!=-1:
flag+=1
print(flag)
for j in range(n):
if a[j]!=-1:
print(c[j])
Learning course: Prepare for your DSA interviews
Problem Link: Practice Problem in - CodeChef