#C6533. Splitting List into Consecutive Patterns

    ID: 50304 Type: Default 1000ms 256MiB

Splitting List into Consecutive Patterns

Splitting List into Consecutive Patterns

You are given a list of integers. Your task is to determine whether it is possible to split the list into exactly \(k\) non-empty continuous subsequences such that each subsequence forms a consecutive pattern where each number increases by one.

A subsequence is considered a consecutive pattern if for every adjacent pair in the subsequence, the difference is exactly 1. You need to decide if, by possibly splitting a longer consecutive sequence into smaller valid patterns, you can obtain exactly \(k\) such patterns.

Read the input from standard input (stdin) and output the results to standard output (stdout).

inputFormat

The first line contains a single integer \(t\) (\(1 \le t \le 50\)) — the number of test cases.

For each test case:

  • The first line contains two integers \(n\) and \(k\) (\(1 \le n \le 100\), \(1 \le k \le n\)) representing the length of the list and the required number of consecutive patterns, respectively.
  • The second line contains \(n\) space-separated integers \(a_1, a_2, \ldots, a_n\) (\(1 \le a_i \le 1000\)), the elements of the list.

outputFormat

For each test case, output a single line containing "YES" if it is possible to split the list into exactly \(k\) consecutive patterns, and "NO" otherwise.

## sample
4
6 2
1 2 3 5 6 7
5 1
3 4 5 6 7
7 3
10 11 12 1 2 3 8
4 4
4 5 6 7
YES

YES YES NO

</p>