File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .Arrays ;
2+ import java .util .Scanner ;
3+ import java .util .stream .IntStream ;
4+
5+ public class Main {
6+ public static void main (String [] args ) {
7+ Scanner sc = new Scanner (System .in );
8+
9+ int t = sc .nextInt ();
10+ for (int tc = 0 ; tc < t ; ++tc ) {
11+ int n = sc .nextInt ();
12+ int [] a = readArray (sc , n );
13+ int [] b = readArray (sc , n );
14+
15+ System .out .println (solve (a , b ) ? "Yes" : "No" );
16+ }
17+
18+ sc .close ();
19+ }
20+
21+ static int [] readArray (Scanner sc , int size ) {
22+ int [] result = new int [size ];
23+ for (int i = 0 ; i < result .length ; ++i ) {
24+ result [i ] = sc .nextInt ();
25+ }
26+
27+ return result ;
28+ }
29+
30+ static boolean solve (int [] a , int [] b ) {
31+ return Arrays .stream (b ).distinct ().count () == 2
32+ || IntStream .range (0 , a .length - 1 ).allMatch (i -> a [i ] <= a [i + 1 ]);
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments