For each test case, decide whether the daily prices contain a strictly increasing subsequence of length K.
Medium4Dynamic programmingBinary searchInterviewNo attempts yetTime limit5sMemory limit512 MBOn the way to work you picked a strange document out of a subway station trash can. It listed one company's stock price day by day, and every date was in the future. You compared the listed values with the real prices and they matched exactly. Maybe a descendant rode a time machine back to help an ancestor.
The stock price for the next N days is given as N integers. You have never traded stock before, so you go to a brokerage and open an account. To avoid suspicion about trading with knowledge of the future, you decide to buy the stock exactly K times. You may buy at most once a day, so you buy on K different days.
To reduce suspicion further, every purchase after the first one must happen on a day whose price is higher than the price on the day of the previous purchase. For example, suppose the prices over 10 days are the following.
| Day | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| Price | 100 | 50 | 70 | 90 | 75 | 87 | 105 | 78 | 110 | 60 |
If K=3, buying on days 2, 3 and 4 gives prices 50, 70, 90, which satisfies the condition. If K=6, buying on days 2, 3, 5, 6, 7 and 9 gives prices 50, 70, 75, 87, 105, 110, which satisfies the condition. If K=10, no choice of days satisfies the condition.
Given N, K and the prices of the N days, write a program that decides whether the purchases can be made under this condition.
The first line contains the number of test cases T (2≤T≤100). The T test cases follow in order.
The first line of each test case contains two integers N and K. N is the number of days whose price you know in advance (1≤N≤10000), and K is the number of purchases (1≤K≤10000). The next line contains the prices of the N days in date order, separated by spaces. Every price is an integer between 1 and 10000.
Print two lines for each test case.
The first line contains Case #t, where t is the test case number counted from 1. The second line contains 1 if the purchases can be made under the condition, and 0 otherwise.