human
Check if all people can vote on two machines | Function returns true if n people can vote using two machines in x time ..
dp [ i ] [ j ] stores maximum possible number of people among arr [ 0. . i - 1 ] can vote in j time ..
Find sum of all times.
Fill dp [ ] [ ] in bottom up manner ( Similar to knapsack ) ..
If remaining people can go to other machine ..
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to check if all people can vote on two machines and the other steps required.
 def canVote ( a , n , x ) :
	dp = [ [ 0 ] * ( x + 1 ) for _ in range ( n + 1 ) ]
	a = a [ : ]
	a . append ( 0 )
	sm = 0
	for i in range ( n + 1 ) :
		sm += a [ i ]
	for i in range ( 1 , n + 1 ) :
		for j in range ( 1 , x + 1 ) :
			if a [ i ] <= j :
				dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , a [ i ] + dp [ i - 1 ] [ j - a [ i ] ] )
			else :
				dp [ i ] [ j ] = dp [ i - 1 ] [ j ]
	return ( sm - dp [ n ] [ x ] ) <= x
if __name__ == " _ _ main _ _ " :
	n = 3
	x = 4
	a = [ 2 , 4 , 2 ]
	print ( " YES " if canVote ( a , n , x ) else " NO " )