infytq minimum withdrawal code example
Example: infytq minimum withdrawal
a=int(input())
b=[]
for i in range(a):
temp=int(input())
b.append(temp)
c=int(input())
if(sum(b)<c):
print(-1)
exit(0)
d=b[::-1]
sum1=0
i=0
j=0
minv=99999
while(i<len(b) and sum1<=c):
sum1=sum1+b[i]
i=i+1
i=i-1
r=i+1
flag=0
if(sum1==c and r<minv):
flag=1
minv=r
while(1):
if(j<len(b) and sum1+d[j]<=c):
sum1=sum1+d[j]
j=j+1
r=r+1
elif(i>=0):
sum1=sum1-b[i]
i=i-1
r=r-1
else:
break
if(sum1==c and r<minv):
minv=r
if(sum1==c and r<minv):
minv=r
if(minv==99999):
print(-1)
else:
print(minv)