Given the values of N drawn cards summing to at most 21, decide whether to draw again based on how many remaining cards exceed the gap to 21.
Easy3ImplementationMathSimulationArrayInterviewNo attempts yetTime limit1sMemory limit64 MBLittle Cezar likes card games. Every time he comes to Zagreb, he plays blackjack with his friends.
In this game a player keeps drawing cards while the sum of the cards in his hand is at most 21, or until he says "DOSTA" (Croatian for "STOP"). At the start of the game the deck holds 52 cards, thirteen ranks in each of the four suits. The ranks are two, three, ..., ten, Jack, Queen, King and Ace. A card with a number on it is worth that number, so a nine is worth 9. A picture card (Jack, Queen, King) is worth 10, and an Ace is worth 11.
Cezar is in an awkward spot. He has already drawn N cards whose sum is at most 21, and he is having second thoughts about drawing one more. Let X be the difference between that sum and 21. Everybody knows that you do not draw a card when the number of cards left in the deck with a value greater than X is greater than or equal to the number of cards left in the deck with a value at most X.
Cezar has a hard time working out whether he should draw again, so he asks you to do it for him.
The first line contains the number of cards Cezar has drawn so far, N (1≤N≤52).
Each of the next N lines contains the value of the i-th card Cezar drew. Every value is between 2 and 11, and the values sum to at most 21.
If Cezar should draw another card, print "VUCI" (Croatian for "DRAW"). Otherwise print "DOSTA" (Croatian for "STOP").
Take the first example. The sum of the drawn cards is 15, so the difference X to 21 is 6. The deck has 32 cards left with a value greater than 6: 4 Aces, 4 Kings, 4 Queens, 4 Jacks, 4 tens, 4 nines, 4 eights and 4 sevens. It has 14 cards left with a value of at most 6: one two, one three, 4 fours, 4 fives and 4 sixes.