human
Minimum count of indices to be skipped for every index of Array to keep sum till that index at most T | Function to calculate minimum indices to be skipped so that sum till i remains smaller than T.
Store the sum of all indices before i.
Store the elements that can be skipped.
Traverse the array , A [ ].
Store the total sum of elements that needs to be skipped.
Store the number of elements need to be removed.
Traverse from the back of map so as to take bigger elements first.
Update sum.
Update map with the current element.
Driver code.
Given Input.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to minimum count of indices to be skipped for every index of Array to keep sum till that index at most T and the other steps required.
 def skipIndices ( N , T , arr ) :
	sum = 0
	count = { }
	for i in range ( N ) :
		d = sum + arr [ i ] - T
		k = 0
		if ( d > 0 ) :
			for u in list ( count . keys ( ) ) [ : : - 1 ] :
				j = u
				x = j * count [ j ]
				if ( d <= x ) :
					k += ( d + j - 1 ) // j
					break
				k += count [ j ]
				d -= x
		sum += arr [ i ]
		count [ arr [ i ] ] = count . get ( arr [ i ] , 0 ) + 1
		print ( k , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	N = 7
	T = 15
	arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ]
	skipIndices ( N , T , arr )