Blackjack BLKJK SOLUTION Code Chef
Blackjack BLKJK SOLUTION Chef is playing a card game called Blackjack. He starts with a deck of N cards (numbered 1 through N), where for each valid i, the i-th card has an integer Ai written on it. Then he starts dealing the cards one by one in the order from card 1 to card N. Chef wins if at some moment in time, the sum of all the cards dealt so far is between X and Y inclusive; if this never happens, Chef loses.
We want Chef to win the game, so without him noticing, we will swap some pairs of cards (possibly none) before the game starts. Find the smallest number of swaps we need so that Chef would win the game, or determine that it is impossible to make Chef win.Blackjack BLKJK SOLUTION
- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains three space-separated integers N, X and Y.
- The second line contains N space-separated integers A1,A2,…,AN.
For each test case, print a single line containing one integer ― the smallest required number of swaps or −1 if Chef cannot win.
1≤Ai≤103 for each valid i
the sum of N over all test cases does not exceed 104
Subtask #1 (22 points): Chef can win if we make up to 2 swaps
Subtask #2 (34 points):
1≤Ai≤400 for each valid i
the sum of N over all test cases does not exceed 4,000
Subtask #3 (44 points): original constraints
3 4 5
1 2 3
3 3 4
1 2 3
2 20 30
- Example case 1: We can swap the last card with one of the first two cards.
- Example case 2: No swaps are necessary, Chef wins after dealing the first two cards.
- Example case 3: The order of the cards in the deck does not matter, Chef cannot win.
January Long Challenge 2021
- Chef and Division 3 DIVTHREE SOLUTION Code Chef
- Encoded String DECODEIT SOLUTION Code Chef
- Point Of Impact BILLRD SOLUTION Code Chef
- Fair Elections FAIRELCT SOLUTION Code Chef
- Watching CPL WIPL SOLUTION Code Chef
- Chef and Ants ANTSCHEF SOLUTION Code Chef
- Blackjack BLKJK SOLUTION Code Chef
- And-Or Game ORAND SOLUTION Code Chef
- Stack-Queue Sort (Challenge) SQSORT SOLUTION Code Chef
- Expected Number of SCCs RCTEXSCC SOLUTION Code Chef
- Curious Matrix CURMAT SOLUTION Code Chef
- Cool Subsets COOLSBST SOLUTION Code Chef
- Sequence Creation ARCRT SOLUTION Code Chef
- Greedy Students GRDSTD SOLUTION Code Chef