Skip to content

Commit 0f52902

Browse files
Trouble Sort
1 parent 9dc185e commit 0f52902

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

1365/B/Main.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

0 commit comments

Comments
 (0)