[Solution] Consecutive Cuts - Chapter 1 Meta Hacker Cup Round 1 Solution
Note: The only difference between this chapter and chapter 2 is that here, all card values are guaranteed to be distinct.
Let's cut to the chase. You have a deck of face-up cards, each displaying a unique integer between and .
Cutting the deck once consists of taking a stack of between and cards from the top and moving it to the bottom in the same order. For example, for the deck ordered from top to bottom, cutting cards from the top would yield :
Initially, the th card from the top is . Is it possible to cut the deck exactly times to reorder the deck such that the th card from the top is for all ?
Constraints
and are each permutations of .
The sum of across all test cases is at most .
Input Format
Input begins with an integer , the number of test cases. For each test case, there is first a line containing two space-separated integers and . Then, there is a line containing space-separated integers, . Then, there is a line containing space-separated integers, .
Output Format
For the th test case, print "Case #i: " followed by "YES" if it's possible to cut the deck times to change the deck from to , or "NO" otherwise.
Sample Explanation
In the first case, it's possible to get to the new order with cut (cutting 2 cards from the top).
In the second case, it's impossible to change to with any number of cuts.
In the third case, it's impossible for the deck to be in a different order after cuts.
No comments:
Post a Comment