atcoder#AGC052D. [AGC052D] Equal LIS
[AGC052D] Equal LIS
Score : points
Problem Statement
You are given a permutation of integers from to . Is it possible to split it into subsequences, which have equal length of the Longest Increasing Subsequence?
Formally speaking, your goal is to get two integer sequences and such that:
- Both and are subsequences of .
- Each integer appears in exactly one of and .
- (The length of a longest increasing subsequence of ) (The length of a longest increasing subsequence of )
Determine if the objective is achievable.
You will be given test cases. Solve each of them.
Constraints
- is a permutation of integers from to .
- The sum of over all test cases doesn't exceed .
Input
Input is given from Standard Input in the following format. The first line of input is as follows:
Then, test cases follow, each of which is in the following format:
Output
For each test case, print YES
if it is possible to split the permutation into subsequences, which have equal length of the Longest Increasing Subsequence, and print NO
otherwise.
Use one line for each case.
Note that the checker is case-insensitive: you can print letters in both uppercase and lowercase.
5
1
1
2
2 1
3
1 2 3
5
1 3 5 2 4
6
2 3 4 5 6 1
NO
YES
NO
YES
NO
can be split into and , both have of length 2.
It can be shown that there is no way to split into subsequences with an equal length of .