human
Give me a code to minimum number of working days required to achieve each of the given scores and the other steps required given the following:
Minimum number of working days required to achieve each of the given scores | Function to find the minimum number of days required to work to at least arr [ i ] points for every array element.
Traverse the array P [ ].
Find the prefix sum.
Traverse the array arr [ ].
Find the minimum index of the array having value at least arr [ i ].
If the index is not - 1.
Otherwise.
Function to find the lower bound of N using binary search.
Stores the lower bound.
Stores the upper bound.
Stores the minimum index having value is at least N.
Iterater while i <= j.
Stores the mid index of the range [ i , j ].
If P [ mid ] is at least N.
Update the value of mid to index.
Update the value of j.
Update the value of i.
Return the resultant index.
Driver Code"
Solution in Python:
assistant
#Here is code to minimum number of working days required to achieve each of the given scores and the other steps required.
 def minDays ( P , arr ) :
	for i in range ( 1 , len ( P ) ) :
		P [ i ] += P [ i ] + P [ i - 1 ]
	for i in range ( len ( arr ) ) :
		index = binarySeach ( P , arr [ i ] )
		if ( index != - 1 ) :
			print ( index + 1 , end = " ▁ " )
		else :
			print ( - 1 , end = " ▁ " )
def binarySeach ( P , N ) :
	i = 0
	j = len ( P ) - 1
	index = - 1
	while ( i <= j ) :
		mid = i + ( j - i ) // 2
		if ( P [ mid ] >= N ) :
			index = mid
			j = mid - 1
		else :
			i = mid + 1
	return index
if __name__ == ' _ _ main _ _ ' :
	arr = [ 400 , 200 , 700 , 900 , 1400 ]
	P = [ 100 , 300 , 400 , 500 , 600 ]
	minDays ( P , arr )