You are given an array
bool apply(int a, int b, int s) {
int C = a;
for (int i = s; i <= N; i++) {
if (C > A[i]) swap(C,A[i]);
}
return C <= b;
}
The operation is successfully applied if and only if the function returns true
. Your task is to determine whether there is some ordering of the operations such that all of the operations can be applied successfully. To ensure the integrity of your solution, there may be up to
Constraints
The sum of
The sum of
Subtask 1 [10%]
The sum of
The sum of
Subtask 2 [20%]
The sum of
The sum of
Subtask 3 [70%]
No additional constraints.
Input Specification
The first line contains an integer
The first line of each test case contains
The second line of each test case contains
The remaining
Output Specification
For each test case, output one line containing YES
if there is an ordering of the operations such that all of the operations can be applied successfully, or NO
otherwise.
Sample Input
1
5 3
3 1 4 1 5
2 3 5
6 1 1
3 2 3
Sample Output
YES
Explanation for Sample
One possible solution is as follows:
- Apply the third operation. This transforms
into . Since at the end of the process and , this operation was applied successfully. - Apply the first operation. This transforms
into . Since at the end of the process and , this operation was applied successfully. - Apply the second operation. This transforms
into . Since at the end of the process and , this operation was applied successfully.
Comments