meetinghilt.blogg.se

Two stacks of cards
Two stacks of cards










two stacks of cards

We print 4 as our answer, because that is the maximum number of integers that can be removed from the two stacks without the sum exceeding x = 10. The image below depicts the integers Nick should choose to remove from the stacks.

two stacks of cards two stacks of cards

The third line contains n space-separated integers for Stack B.įor each of the g games, print an integer on a new line denoting the maximum possible score Nick can achieve without being disqualified.The second line contains n space-separated integers for Stack A.The first line contains three space-separated integers describing the respective values of n (the number of integers in stack A), m (the number of integers in stack B), and x (the number that the sum of the integers removed from the two stacks cannot exceed).g subsequent lines describe each game in the following format: The first line contains an integer, g (the number of games). Given A, B, and x for g games, find the maximum possible score Nick can achieve (i.e., the maximum number of integers he can remove without being disqualified) during each game and print it on a new line. Nick's final score is the total number of integers he has removed from the two stacks.Nick is disqualified from the game if, at any point, his running sum becomes greater than some integer x given at the beginning of the game.Nick keeps a running sum of the integers he removes from the two stacks.In each move, Nick can remove one integer from the top of either stack A or stack B.Alexa challenges Nick to play the following game: Program: HackerRank stack problem - Game Of Two Stacks.Īlexa has two stacks of non-negative integers, stack A and stack B where index 0 denotes the top of the stack.












Two stacks of cards