#C9856. Can the Arrays be Sorted Satisfactorily?

    ID: 53995 Type: Default 1000ms 256MiB

Can the Arrays be Sorted Satisfactorily?

Can the Arrays be Sorted Satisfactorily?

You are given two arrays A and B, each containing N integers. Your task is to determine if it is possible to sort both arrays (independently) so that for every index i (using 0-indexing), the condition \(A[i] \leq B[i]\) holds true.

Note: You are allowed to sort the arrays in any order. The ordering of elements in A and B can be changed independently.

The problem can be formulated mathematically as follows:

Given two sequences \(A = [a_1, a_2, \dots, a_N]\) and \(B = [b_1, b_2, \dots, b_N]\), determine if there exist permutations \(A'\) and \(B'\) of A and B respectively such that \(a'_i \leq b'_i\) for every \(1 \leq i \leq N\). In particular, a sufficient strategy is to sort both arrays in non-decreasing order and then check if \(a'_i \leq b'_i\) holds for each index.

If the condition holds for all indices, print "Yes"; otherwise, print "No".

inputFormat

Input is read from standard input (stdin). The first line contains a single integer \(N\), representing the number of elements in each array. The second line contains \(N\) integers separated by spaces, representing the elements of array A. The third line contains \(N\) integers separated by spaces, representing the elements of array B.

outputFormat

Output should be printed to standard output (stdout). Print a single line containing either "Yes" if the arrays can be sorted such that for every index \(i\), \(A[i] \leq B[i]\) holds, or "No" otherwise.

## sample
4
1 3 5 7
2 4 6 8
Yes