exec_outcome
stringclasses
1 value
code_uid
stringlengths
32
32
file_name
stringclasses
111 values
prob_desc_created_at
stringlengths
10
10
prob_desc_description
stringlengths
63
3.8k
prob_desc_memory_limit
stringclasses
18 values
source_code
stringlengths
117
65.5k
lang_cluster
stringclasses
1 value
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_time_limit
stringclasses
27 values
prob_desc_sample_outputs
stringlengths
2
796
prob_desc_notes
stringlengths
4
3k
lang
stringclasses
5 values
prob_desc_input_from
stringclasses
3 values
tags
listlengths
0
11
src_uid
stringlengths
32
32
prob_desc_input_spec
stringlengths
28
2.37k
difficulty
int64
-1
3.5k
prob_desc_output_spec
stringlengths
17
1.47k
prob_desc_output_to
stringclasses
3 values
hidden_unit_tests
stringclasses
1 value
PASSED
b84cf14102b216de4ea16c03ac08999d
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 < i_2 < \ldots < i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
/***** ---> :) Vijender Srivastava (: <--- *****/ import java.util.*; import java.lang.*; import java.lang.reflect.Array; import java.io.*; public class Main { static FastReader sc =new FastReader(); static PrintWriter out=new PrintWriter(System.out); static long mod=998244353; /* start */ public static void main(String [] args) { // int testcases = 1; int testcases = i(); while(testcases-->0) { solve(); } out.flush(); out.close(); } static void solve() { int n = i(); int a[] = input(n); int b[] = input(n); sort(a); sort(b); for(int i=0;i<n;i++) { if(a[i]!=b[i] && a[i]+1!=b[i]) { pl("NO"); return; } } pl("YES"); } /* end */ static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static void p(Object o) { out.print(o); } static void pl(Object o) { out.println(o); } static int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } static char[] inputC() { String s = sc.nextLine(); return s.toCharArray(); } static int[] input(int n) { int A[]=new int[n]; for(int i=0;i<n;i++) { A[i]=sc.nextInt(); } return A; } static long[] inputL(int n) { long A[]=new long[n]; for(int i=0;i<n;i++) { A[i]=sc.nextLong(); } return A; } static long[] putL(long a[]) { long A[]=new long[a.length]; for(int i=0;i<a.length;i++) { A[i]=a[i]; } return A; } static String[] inputS(int n) { String A[]=new String[n]; for(int i=0;i<n;i++) { A[i]=sc.next(); } return A; } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static String reverse(String s) { StringBuffer p=new StringBuffer(s); p.reverse(); return p.toString(); } static int min(int a,int b) { return Math.min(a, b); } static int min(int a,int b,int c) { return Math.min(a, Math.min(b, c)); } static int min(int a,int b,int c,int d) { return Math.min(a, Math.min(b, Math.min(c, d))); } static int max(int a,int b) { return Math.max(a, b); } static int max(int a,int b,int c) { return Math.max(a, Math.max(b, c)); } static int max(int a,int b,int c,int d) { return Math.max(a, Math.max(b, Math.max(c, d))); } static long min(long a,long b) { return Math.min(a, b); } static long min(long a,long b,long c) { return Math.min(a, Math.min(b, c)); } static long min(long a,long b,long c,long d) { return Math.min(a, Math.min(b, Math.min(c, d))); } static long max(long a,long b) { return Math.max(a, b); } static long max(long a,long b,long c) { return Math.max(a, Math.max(b, c)); } static long max(long a,long b,long c,long d) { return Math.max(a, Math.max(b, Math.max(c, d))); } static long sum(int A[]) { long sum=0; for(int i : A) { sum+=i; } return sum; } static long sum(long A[]) { long sum=0; for(long i : A) { sum+=i; } return sum; } static void print(int A[]) { for(int i : A) { System.out.print(i+" "); } System.out.println(); } static void print(long A[]) { for(long i : A) { System.out.print(i+" "); } System.out.println(); } static long mod(long x) { return ((x%mod + mod)%mod); } static long power(long x, long y) { if(y==0) return 1; if(x==0) return 0; long res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x) ; y = y >> 1; x = (x * x); } return res; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static long[] sort(long a[]) { ArrayList<Long> arr = new ArrayList<>(); for(long i : a) { arr.add(i); } Collections.sort(arr); for(int i = 0; i < arr.size(); i++) { a[i] = arr.get(i); } return a; } static int[] sort(int a[]) { ArrayList<Integer> arr = new ArrayList<>(); for(Integer i : a) { arr.add(i); } Collections.sort(arr); for(int i = 0; i < arr.size(); i++) { a[i] = arr.get(i); } return a; } //pair class private static class Pair implements Comparable<Pair> { int first, second; public Pair(int f, int s) { first = f; second = s; } @Override public int compareTo(Pair p) { if (first > p.first) return 1; else if (first < p.first) return -1; else { if (second < p.second) return 1; else if (second > p.second) return -1; else return 0; } } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
8986243d9360f92170df8839bb89984c
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.*; import java.util.*; public class C_Two_Arrays { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int a[] = sc.readArray(n); int b[] = sc.readArray(n); sort(a); sort(b); int f = 1; for (int i = 0; i < n; i++) if (a[i] == b[i] || a[i] + 1 == b[i]) continue; else { f = 0; out.println("NO"); break; } if (f == 1) out.println("YES"); } out.close(); } public static PrintWriter out; public static long mod = (long) 1e9 + 7; public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static void dfs(int root, boolean[] vis, int[] value, ArrayList[] gr, int prev) { vis[root] = true; value[root] = 3 - prev; prev = 3 - prev; for (int i = 0; i < gr[root].size(); i++) { int next = (int) gr[root].get(i); if (!vis[next]) dfs(next, vis, value, gr, prev); } } static boolean isPrime(int n) { for (int i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } static int abs(int a) { return a > 0 ? a : -a; } static int max(int a, int b) { return a > b ? a : b; } static int min(int a, int b) { return a < b ? a : b; } static long pow(long n, long m) { if (m == 0) return 1; long temp = pow(n, m / 2); long res = ((temp * temp) % mod); if (m % 2 == 0) return res; return (res * n) % mod; } static class Pair { int u, v; Pair(int u, int v) { this.u = u; this.v = v; } static void sort(Pair[] coll) { List<Pair> al = new ArrayList<>(Arrays.asList(coll)); Collections.sort(al, new Comparator<Pair>() { public int compare(Pair p1, Pair p2) { return p1.u - p2.u; } }); for (int i = 0; i < al.size(); i++) { coll[i] = al.get(i); } } } static void sort(int[] a) { ArrayList<Integer> list = new ArrayList<>(); for (int i : a) list.add(i); Collections.sort(list); for (int i = 0; i < a.length; i++) a[i] = list.get(i); } static void sort(long a[]) { ArrayList<Long> list = new ArrayList<>(); for (long i : a) list.add(i); Collections.sort(list); for (int i = 0; i < a.length; i++) a[i] = list.get(i); } static int[] array(int n, int value) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = value; return a; } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
181f502375f5e7a34fe8645035d6cedc
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class Main { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int arr1[]=new int[n],arr2[]=new int[n]; boolean flag=true; for(int i=0;i<n;i++){ arr1[i]=sc.nextInt(); } for(int i=0;i<n;i++){ arr2[i]=sc.nextInt(); } Arrays.sort(arr1); Arrays.sort(arr2); for(int i=0;i<n;i++){ if(arr1[i]==arr2[i] || (arr1[i]+1)==arr2[i]) continue; flag=false; break; } System.out.println(flag?"YES":"NO"); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
a7377a242eb65eb47bcc3787cae9c10e
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*;//import static java.lang.System.out; import static java.lang.System.*; public class Main { static int[] arr; public static void main(String[] args) throws Exception { int t = A.nextInt(); for (int zzz = 0; zzz < t; zzz++) { int n = A.nextInt(); int[] arr = new int[n]; int[] arr2 = new int[n]; for (int i = 0; i < n; i++) arr[i] = A.nextInt(); for (int i = 0; i < n; i++) arr2[i] = A.nextInt(); boolean b = true; Arrays.sort(arr); Arrays.sort(arr2); for (int i = 0; b && i < n; i++) b = arr2[i]-1 == arr[i] || arr2[i] == arr[i]; if (b) out.println("YES"); else out.println("NO"); } out.close(); } public static class A { public static long pow(long a, long b, long mod) { if (b == 0) return 1; long p = pow(a, b / 2, mod) % mod; return ((p * p) % mod * Math.max(b % 2 * a, 1)) % mod; } static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } static long lcm(long a, long b) { return a / gcd(a, b) * b; } static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer in = new StringTokenizer(""); static PrintWriter out = new PrintWriter(System.out); public static String nextToken() throws IOException { while (in == null || !in.hasMoreTokens()) in = new StringTokenizer(br.readLine()); return in.nextToken(); } public static Double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } public static int nextInt() throws IOException { return Integer.parseInt(nextToken()); } public static long nextLong() throws IOException { return Long.parseLong(nextToken()); } public static String nextLine() throws IOException { return br.readLine(); } } } class O implements Comparable<O> { int a; public O(int a) { this.a = a; } @Override public int compareTo(O o) { return -Integer.compare(Main.arr[o.a], Main.arr[a]); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
cb8d3f354b47abcd9244fb07e941f915
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
// package FunTime; import java.io.BufferedReader; import java.util.*; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.math.*; public class Template { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } boolean hasNext() { if (st != null && st.hasMoreTokens()) { return true; } String tmp; try { br.mark(1000); tmp = br.readLine(); if (tmp == null) { return false; } br.reset(); } catch (IOException e) { return false; } return true; } } public static long gcd(long a, long b) { BigInteger A=new BigInteger(Long.toString(a)); BigInteger B=new BigInteger(Long.toString(b)); return A.gcd(B).longValue(); } public static void main(String[] args) { FastReader sc=new FastReader(); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); pair arr[]=new pair[n]; pair brr[]=new pair[n]; for(int i=0;i<n;i++) { int temp=sc.nextInt(); pair p=new pair(temp,i); arr[i]=p; } for(int i=0;i<n;i++) { int temp=sc.nextInt(); pair p=new pair(temp,i); brr[i]=p; } Arrays.sort(arr); Arrays.sort(brr); // for(int i=0;i<n;i++) { // System.out.print(arr[i].x+" "); // } // System.out.println(); // for(int i=0;i<n;i++) { // System.out.print(brr[i].x+" "); // } // System.out.println(); // // ArrayList<Integer> a=new ArrayList(); boolean flag=false; for(int i=0;i<n;i++) { if(arr[i].x==brr[i].x) { continue; } else if(arr[i].x+1!=brr[i].x) { System.out.println("NO"); flag=true; break; } // else if(arr[i].x+1==brr[i].x) { // a.add(arr[i].y); // } } if(flag) continue; // System.out.println("a--> "+a); // Collections.sort(a); // for(int i=1;i<a.size();i++) { // if(a.get(i)-1!=a.get(i-1)) { // System.out.println("NO"); // flag=true; // break; // } // } // if(flag) continue; System.out.println("YES"); } } } class pair implements Comparable<pair>{ int x,y; pair(int x,int y){ this.x=x; this.y=y; } public int compareTo(pair o1) { return this.x-o1.x; } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
a8ff743b4313c2771f32b39dbfb489e6
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.Arrays; import java.util.Scanner; import java.util.StringTokenizer; public class Template { private static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader scanner = new FastReader(); int tests = scanner.nextInt(); while (tests > 0) { tests--; int size = scanner.nextInt(); int[] a = new int[size]; int[] b = new int[size]; for (int i = 0; i < size; i++) { a[i] = scanner.nextInt(); } for (int i = 0; i < size; i++) { b[i] = scanner.nextInt(); } Arrays.sort(a); Arrays.sort(b); if(work(a,b)) { System.out.println("YES"); } else { System.out.println("NO"); } } } private static boolean work(int[] a, int[] b) { for (int i = 0; i < a.length; i++) { if(b[i]-a[i] > 1 || a[i] > b[i]) { return false; } } return true; } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
83c9e53f12845a80b64088eb780beee1
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class CForce { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); while (t-->0){ int n = scan.nextInt(); int ar[] = new int[n]; int ar1[] = new int[n]; for (int i = 0; i < n; i++) { ar[i] = scan.nextInt(); } Arrays.sort(ar); for (int i = 0; i < n; i++) { ar1[i] = ( scan.nextInt()); } Arrays.sort(ar1); // System.out.println(Arrays.toString(ar)+" "+Arrays.toString(ar1)); // for (int i = 0; i < n; i++) { // int m = ar[i]; // ar[i] = m-ar1[i]; // } System.out.println(ret(ar , ar1)); } } public static String ret(int arr[] ,int arr1[]){ for (int i = 0; i < arr.length; i++) { if( arr[i] == arr1[i] || arr[i]+1 == arr1[i] ) continue; else return "NO"; } return "YES"; } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
9824a5fd0b3b52d272c9d81a98753027
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class problem1584C { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t != 0) { t--; int n = sc.nextInt(); int a[] = new int[n]; int b[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { b[i] = sc.nextInt(); } solve(n, a, b); } } static void solve(int arraysize, int A[], int B[]) { Arrays.sort(A); Arrays.sort(B); int count = 0; for (int i = 0; i < arraysize; i++) { if (A[i] == B[i]) { count++; } else { if (A[i] + 1 == B[i]) { count++; } } } System.out.println(count == arraysize ? "YES" : "NO"); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
a92a66b94b14a44fc38fb0b6a576bfb7
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class twoarrays { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int t= sc.nextInt(); for(int i=0; i<t; i++){ int n = sc.nextInt(); int[] a= new int[n]; for(int j=0;j<n; j++){ a[j]= sc.nextInt(); } int[] b= new int[n]; for(int k=0;k<n; k++){ b[k]= sc.nextInt(); } Arrays.sort(a); Arrays.sort(b); boolean f=false; for(int l=0; l<n; l++){ if(b[l]-a[l]>=2 || b[l]-a[l]<0) { f=true; break; } } if(f==true) { System.out.println("no"); } else { System.out.println("yes"); } } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
dcbae0272e12a81b0886df9681b2f4b4
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class C_Two_Arrays{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int testCases = scan.nextInt(); while(testCases-->0){ int length = scan.nextInt(); int[] a1 = new int[length]; int[] a2 = new int[length]; for(int i = 0;i<length;i++){ a1[i] = scan.nextInt(); } for(int k = 0;k<length;k++){ a2[k] = scan.nextInt(); } Arrays.sort(a1); Arrays.sort(a2); boolean possible = true; for(int i = 0;i<length;i++){ int difference = a2[i]-a1[i]; if(difference>1 || a1[i]>a2[i]){ possible =false; } } if(possible){ System.out.println("YES"); }else{ System.out.println("NO"); } } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
29703307f33d8c6ba830c860df6b9bb6
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main (String[] args) throws java.lang.Exception { Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t>0) { t--; int n=s.nextInt(); int a[]=new int[n]; int b[]=new int[n]; for(int i=0;i<n;i++) { a[i]=s.nextInt(); } for(int i=0;i<n;i++) { b[i]=s.nextInt(); } String sol="YES"; Arrays.sort(a); Arrays.sort(b); for(int i=0;i<n;i++) { if(b[i]-a[i]!=1 && b[i]-a[i]!=0) { sol="NO";break; } } System.out.println(sol); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
e82d46cb4185e2232c47e38f1b1786d8
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class C { public static void main(String[] args) throws java.lang.Exception { try { FastReader sc = new FastReader(); int t = sc.nextInt(); u: while (t-- > 0) { int n = sc.nextInt(); int arr[]=sc.readArray(n); int arr1[]=sc.readArray(n); Arrays.sort(arr); Arrays.sort(arr1); for(int i=0;i<n;i++) { if(arr[i]!=arr1[i]) { if((arr[i]+1)==arr1[i] ) continue; else { System.out.println("NO"); continue u; } } } System.out.println("YES"); } } catch (Exception e) { } finally { return; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
5ed456d1a3c19850a499e28a5ee31684
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int j = 0; j < T; j++) { int n = sc.nextInt(); int a[] = new int[n]; int b[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { b[i] = sc.nextInt(); } Arrays.sort(a); Arrays.sort(b); boolean flag = true; for (int i = 0; i < n; i++) { if (a[i] == b[i] || a[i] + 1 == b[i]) { continue; } else { System.out.println("NO"); flag = false; break; } } if (flag) { System.out.println("YES"); } } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
cb83916c581e3041847bf928c10e26ae
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; import java.io.*; public class Practice { static boolean multipleTC = true; FastReader in; PrintWriter out; static int mod = 1000000007; public static void main(String[] args) throws Exception { new Practice().run(); } void run() throws Exception { in = new FastReader(); out = new PrintWriter(System.out); int T = (multipleTC) ? ni() : 1; pre(); for (int t = 1; t <= T; t++) solve(t); out.flush(); out.close(); } void pre() throws Exception { } void solve(int TC) throws Exception { int n = ni(); int a[] = new int[n]; int b[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = ni(); } for (int i = 0; i < n; i++) { b[i] = ni(); } sort(a); sort(b); for(int i=0;i< n;i++) { if(b[i]-a[i] > 1 || b[i] -a[i] < 0) { pn("NO"); return; } } pn("YES"); } boolean isSorted(int arr[]) { for (int i = 1; i < arr.length; i++) { if (arr[i] < arr[i - 1]) { return false; } } return true; } static int bitCount(int x) { return x == 0 ? 0 : (1 + bitCount(x & (x - 1))); } void sort(int arr[]) { ArrayList<Integer> list = new ArrayList<>(); for (int i = 0; i < arr.length; i++) list.add(arr[i]); Collections.sort(list); for (int i = 0; i < arr.length; i++) arr[i] = list.get(i); } static void dbg(Object... o) { System.err.println(Arrays.deepToString(o)); } public static boolean isPrime(long n) { if (n < 2) return false; if (n == 2 || n == 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; long sqrtN = (long) Math.sqrt(n) + 1; for (long i = 6L; i <= sqrtN; i += 6) { if (n % (i - 1) == 0 || n % (i + 1) == 0) return false; } return true; } public static long gcd(long a, long b) { if (a > b) a = (a + b) - (b = a); if (a == 0L) return b; return gcd(b % a, a); } public long pow(long base, long exp, long MOD) { base %= MOD; long res = 1; while (exp > 0) { if ((exp & 1) == 1) res = res * base % MOD; base = base * base % MOD; exp >>= 1; } return res; } public static long totient(long n) { long result = n; for (int p = 2; p * p <= n; ++p) if (n % p == 0) { while (n % p == 0) n /= p; result -= result / p; } if (n > 1) result -= result / n; return result; } int bit(long n) { return (n == 0) ? 0 : (1 + bit(n & (n - 1))); } public long max(long... arr) { long max = arr[0]; for (long itr : arr) max = Math.max(max, itr); return max; } public int max(int... arr) { int max = arr[0]; for (int itr : arr) max = Math.max(max, itr); return max; } public long min(long... arr) { long min = arr[0]; for (long itr : arr) min = Math.min(min, itr); return min; } public int min(int... arr) { int min = arr[0]; for (int itr : arr) min = Math.min(min, itr); return min; } public long sum(long... arr) { long sum = 0; for (long itr : arr) sum += itr; return sum; } public long sum(int... arr) { long sum = 0; for (int itr : arr) sum += itr; return sum; } void p(Object o) { out.print(o); } void pn(Object o) { out.println(o); } void pni(Object o) { out.println(o); out.flush(); } String n() throws Exception { return in.next(); } String nln() throws Exception { return in.nextLine(); } int ni() throws Exception { return Integer.parseInt(in.next()); } long nl() throws Exception { return Long.parseLong(in.next()); } double nd() throws Exception { return Double.parseDouble(in.next()); } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws Exception { br = new BufferedReader(new FileReader(s)); } String next() throws Exception { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new Exception(e.toString()); } } return st.nextToken(); } String nextLine() throws Exception { String str = ""; try { str = br.readLine(); } catch (IOException e) { throw new Exception(e.toString()); } return str; } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
747fd9659bcf435d223be75c6cf091bd
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0){ int n = sc.nextInt(); int [] a = new int[n]; int [] b = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { b[i] = sc.nextInt(); } Arrays.sort(a); Arrays.sort(b); int i = 0; for (; i < b.length; i++) { if(a[i]==b[i] || a[i]+1==b[i])continue; else{ System.out.println("NO"); break; } } if(i==b.length)System.out.println("YES"); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
a93e2f4b4bf550b548140f8521d987c8
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Set; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.StringTokenizer; import java.util.TreeSet; public class C_Two_Arrays { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; ; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { try { FastReader s = new FastReader(); int t = s.nextInt(); while (t-- > 0) { int n = s.nextInt(); ArrayList<Integer> al = new ArrayList<>(); ArrayList<Integer> bl = new ArrayList<>(); int suma = 0; int sumb = 0; for (int i = 0; i < n; i++) { al.add(s.nextInt()); suma += al.get(i); } for (int i = 0; i < n; i++) { bl.add(s.nextInt()); sumb += bl.get(i); } Collections.sort(al); Collections.sort(bl); int c = 0; for (int i = 0; i < n; i++) { if (al.get(i) == bl.get(i) || al.get(i) + 1 == bl.get(i)) { c++; } else { System.out.println("NO"); break; } } if (c == n) System.out.println("YES"); } } catch (Exception e) { return; } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
259f87707bd1936596a6388a61bb5a4e
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
// package com.company.Codeforces; import java.util.*; import java.lang.*; import java.io.*; public class newPro { public static void solve(){ int n = sc.nextInt(); int [] a = sc.nextIntArray(n); int [] b = sc.nextIntArray(n); Arrays.sort(a); Arrays.sort(b); for(int i=0; i<n; i++){ if(a[i] != b[i] && a[i]+1 != b[i]){ str.append("NO"); return; } } str.append("YES"); } static PrintWriter out; static StringBuilder str; static Scanner sc; public static void main (String[] args) throws java.lang.Exception { sc = new Scanner(); str = new StringBuilder(); out = new PrintWriter(System.out); int t = sc.nextInt(); while(t-->0){ solve(); str.append('\n'); } out.println(str); out.close(); } private static long power(long a, long b) { long res = 1; while (b > 0) { if ((b & 1)==1) res = res * a; a = a * a; b >>= 1; } return res; } private static long power(long a, long b, long m) { a %= m; long res = 1; while (b > 0) { if ((b & 1)==1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } private static long lcm(long a, long b) { return a * b / gcd(a, b); } private static long gcd(long a, long b) { return (b == 0) ? a : gcd(b, a % b); } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() { br = new BufferedReader(new InputStreamReader(System.in)); /* try { br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("file_i_o\\input.txt")))); } catch (FileNotFoundException e) { e.printStackTrace(); } */ } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] nextIntArray(int n) { int[] array = new int[n]; for (int i = 0; i < n; i++) { array[i] = nextInt(); } return array; } Integer[] nextIntegerArray(int n) { Integer[] array = new Integer[n]; for (int i = 0; i < n; i++) { array[i] = nextInt(); } return array; } long[] nextLongArray(int n) { long[] array = new long[n]; for (int i = 0; i < n; i++) { array[i] = nextLong(); } return array; } String[] nextStringArray() { return nextLine().split(" "); } String[] nextStringArray(int n) { String[] array = new String[n]; for (int i = 0; i < n; i++) { array[i] = next(); } return array; } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
435ed0b3641cfead4f3a35ddbde71acd
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class B { public static void main(String[] args) { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = fs.nextInt(); while (t-- > 0) { int n = fs.nextInt(); int arr[]=fs.readArray(n); int arr1[]=fs.readArray(n); sort(arr, 0); sort(arr1, 0); System.out.println(check(n,arr,arr1)); } // out.close(); } public static String check(int n,int arr[],int arr1[]){ for(int i=0;i<n;i++){ if(arr1[i]<arr[i]){ return "NO"; } if(arr1[i]-arr[i]>1){ return "NO"; } } return "YES"; } /* HELPER FUNCTION's */ static final Random random = new Random(); static final int mod = 1_000_000_007; static void ruffleSort(int[] a) { int n = a.length;//shuffle, then sort for (int i = 0; i < n; i++) { int oi = random.nextInt(n), temp = a[oi]; a[oi] = a[i]; a[i] = temp; } Arrays.sort(a); } static long add(long a, long b) { return (a + b) % mod; } static long sub(long a, long b) { return ((a - b) % mod + mod) % mod; } static long mul(long a, long b) { return (a * b) % mod; } /* fast exponentiation */ static long exp(long base, long exp) { if (exp == 0) return 1; long half = exp(base, exp / 2); if (exp % 2 == 0) return mul(half, half); return mul(half, mul(half, base)); } /* end of fast exponentiation */ static long[] factorials = new long[2_000_001]; static long[] invFactorials = new long[2_000_001]; static void precompFacts() { factorials[0] = invFactorials[0] = 1; for (int i = 1; i < factorials.length; i++) factorials[i] = mul(factorials[i - 1], i); invFactorials[factorials.length - 1] = exp(factorials[factorials.length - 1], mod - 2); for (int i = invFactorials.length - 2; i >= 0; i--) invFactorials[i] = mul(invFactorials[i + 1], i + 1); } static long nCk(int n, int k) { return mul(factorials[n], mul(invFactorials[k], invFactorials[n - k])); } /* sort ascending and descending both */ static void sort(int[] a,int x) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); if(x==0) { Collections.sort(l); } if(x==1){ Collections.sort(l,Collections.reverseOrder()); } for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void sortL(long[] a,int x) { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); if(x==0) { Collections.sort(l); } if(x==1){ Collections.sort(l,Collections.reverseOrder()); } for (int i = 0; i < a.length; i++) a[i] = l.get(i); } /* sort String acc. to character */ static String sortString(String s){ char ch[]=s.toCharArray(); Arrays.sort(ch); String s1=String.valueOf(ch); return s1; } // lcm(a,b) * gcd(a,b) = a * b public static long _lcm(long a, long b) { return (a / _gcd(a, b)) * b; } // euclidean algorithm time O(max (loga ,logb)) public static long _gcd(long a, long b) { while (a > 0) { long x = a; a = b % a; b = x; } return b; } /* Pair Class implementation */ static class Pair<K, V> { K ff; V ss; public Pair(K ff, V ss) { this.ff = ff; this.ss = ss; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || this.getClass() != o.getClass()) return false; Pair<?, ?> pair = (Pair<?, ?>) o; return ff.equals(pair.ff) && ss.equals(pair.ss); } @Override public int hashCode() { return Objects.hash(ff, ss); } @Override public String toString() { return ff.toString() + " " + ss.toString(); } } /* pair class ends here */ /* fast input output class */ static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readArrayL(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
8c031957660580e748230ac2ce9b6253
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class TwoArrays { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for ( int p = 0; p < t; p++){ int n = in.nextInt(); int[] arr1 = new int[n]; int[] arr2 = new int[n]; for ( int i = 0; i < n; i++) arr1[i] = in.nextInt(); for ( int i = 0; i < n; i++) arr2[i] = in.nextInt(); int test = 0; Arrays.sort(arr1); Arrays.sort(arr2); for ( int i = 0; i < n; i++){ if ( arr1[i] != arr2[i] && arr1[i] + 1 != arr2[i]){ System.out.println("NO"); test = -1; break; } } if ( test == 0 ) System.out.println("YES"); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
af36fb6a61410a885b97cdb4da981bcd
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.FileNotFoundException; import java.sql.Array; import java.util.*; public class template { public static void main(String[] args) throws FileNotFoundException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int a = 0; a < t; a++) { int n = sc.nextInt(); ArrayList<Integer> arr1 = new ArrayList<>(); ArrayList<Integer> arr2 = new ArrayList<>(); for (int b = 0; b < n; b++) { arr1.add(sc.nextInt()); } for (int b = 0; b < n; b++) { arr2.add(sc.nextInt()); } System.out.println(output(arr1, arr2)); } } public static String output(ArrayList<Integer> arr1, ArrayList<Integer> arr2) { Collections.sort(arr1); Collections.sort(arr2); for (int i = 0; i < arr1.size(); i++) { if (arr1.get(i) != arr2.get(i) && arr1.get(i)+1 != arr2.get(i)) return "NO"; } return "YES"; } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
364e7a4f0c849145ef6f0fe14d56b695
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import javax.management.ValueExp; import javax.sql.rowset.spi.SyncResolver; import java.io.ObjectInputStream.GetField; import java.lang.*; /* Name of the class has to be "Main" only if the class is public. */ public class codeforces { public static void main(String[] args) { //public stHashSet<String> setha={"00"}; Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int a[]=new int[n]; int b[]=new int[n]; for(int i=0;i<n;i++){ a[i]=sc.nextInt()+1; } for(int i=0;i<n;i++){ b[i]=sc.nextInt(); } Arrays.sort(a); Arrays.sort(b); boolean out=false; for(int i=0;i<n;i++){ if(a[i]==b[i]||a[i]-1==b[i]){ continue; } out=true; break; } if(out){ System.out.println("NO"); }else{ System.out.println("YES"); } } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
ae3bad70f5bc16d238f616e12d741704
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.*; import java.util.*; public class Main { static class FastReader { BufferedReader br;StringTokenizer st;public FastReader(){ br = new BufferedReader(new InputStreamReader(System.in));} String next(){while(st==null||!st.hasMoreElements()) { try{st=new StringTokenizer(br.readLine());}catch(IOException e){ e.printStackTrace();}}return st.nextToken();} int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble(){return Double.parseDouble(next());} String nextLine(){String str = "";try {str = br .readLine();} catch (IOException e) {e.printStackTrace();}return str;} } static FastReader sc = new FastReader(); public static void main(String[] args) { StringBuilder ans = new StringBuilder(); int t = sc.nextInt(); // int t=1; while(t-->0){ans.append(solve()).append("\n");} System.out.print(ans); } static String solve(){ int n = sc.nextInt(); int[] a = new int[n]; for(int i=0;i<n;i++){ a[i] = sc.nextInt(); } int[] b = new int[n]; for(int i=0;i<n;i++){ b[i] = sc.nextInt(); } Arrays.sort(a); Arrays.sort(b); for(int i=0;i<n;i++){ if(b[i]==a[i] ||b[i] == (a[i]+1)); else return "NO"; } return "YES"; } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
0a62166528b7830dfc07ec263ef7a95e
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; import java.io.*; public class Main { // when can't think of anything -->> // 1. In sorting questions try to think about all possibilities like sorting from start, end, middle. // 2. Two pointers, brute force. // 3. In graph query questions try to solve it reversely or try to process all the queries in a single parse. // 4. If order does not matter then just sort the data if constraints allow. It'll never harm. // 5. In greedy problems if you are just overwhelmed by the possibilities and stuck, try to code whatever you come up with. // 6. Think like a robot, just consider all the possibilities not probabilities if you still can't solve. // 7. Try to solve it from back or reversely. public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); PrintWriter writer = new PrintWriter(System.out); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int arr1[] = new int[n]; int arr2[] = new int[n]; for(int i = 0; i < n; i++) { arr1[i] =sc.nextInt(); } for(int i = 0; i < n; i++) { arr2[i] =sc.nextInt(); } Arrays.sort(arr1); Arrays.sort(arr2); boolean ans = true; for(int i = n-1; i >= 0; i--) { if(arr1[i] == arr2[i] || (arr1[i]+1 == arr2[i]) )continue; ans = false; break; } if(ans)writer.println("YES"); else writer.println("NO"); } writer.flush(); writer.close(); } private static boolean isPrime(int c) { for (int i = 2; i*i <= c; i++) { if(c%i==0)return false; } return true; } private static int find(int a , int arr[]) { if(arr[a] != a) return arr[a] = find(arr[a], arr); return arr[a]; } private static void union(int a, int b, int arr[]) { int aa = find(a,arr); int bb = find(b, arr); arr[aa] = bb; } private static int gcd(int a, int b) { if(a==0)return b; return gcd(b%a, a); } public static int[] readIntArray(int size, FastReader s) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = s.nextInt(); } return array; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } class Pair implements Comparable<Pair>{ int a; int b; Pair(int a, int b){ this.a = a; this.b = b; } @Override public boolean equals(Object obj) { if(this == obj) return true; if(obj == null || obj.getClass()!= this.getClass()) return false; Pair pair = (Pair) obj; return (pair.a == this.a && pair.b == this.b); } @Override public int hashCode() { return Objects.hash(a,b); } @Override public int compareTo(Pair o) { if(this.a == o.a) { return Integer.compare(this.b, o.b); }else { return Integer.compare(this.a, o.a); } } @Override public String toString() { return this.a + " " + this.b; } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
16af5a45a0e657424677e4ef0a553b1a
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class C { public static void main(String[] args) { Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(System.out); int T = in.nextInt(); for (int t = 0; t < T; t++) { int n = in.nextInt(); List<Integer> a = new ArrayList<>(n); List<Integer> b = new ArrayList<>(n); for (int i = 0; i < n; i++) { a.add(in.nextInt()); } for (int i = 0; i < n; i++) { b.add(in.nextInt()); } Collections.sort(a); Collections.sort(b); boolean y = true; for (int i = 0; i < n; i++) { if (!a.get(i).equals(b.get(i)) && a.get(i) + 1 != b.get(i)) { y = false; break; } } out.println(y ? "YES" : "NO"); } out.close(); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
3bd5a460d8bfe3a4deff44b64a7e1dc9
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class TwoArrays { public static void main(String[] args) { Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int i=0;i<t;i++){ int n=in.nextInt(); int []a=new int [n]; int[] b=new int [n]; for(int j=0;j<n;j++) a[j]=in.nextInt(); for(int j=0;j<n;j++) b[j]=in.nextInt(); Arrays.sort(a); Arrays.sort(b); String str="YES"; for(int j=0;j<n;j++){ if(a[j]==b[j]) continue; else if(a[j]>b[j]) { str="NO"; break; } else { if(a[j]+1==b[j]) continue; else { str="NO"; break; } } } System.out.println(str); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
55ce52053e568a3af054720e33213f97
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; import java.io.*; import java.lang.reflect.Array; public class codeforce { public static void main(String[] args){ Scanner read = new Scanner(System.in); byte t = read.nextByte(); while(t-->0){ int n = read.nextInt(); int[] arr1 = new int[n]; int[] arr2 = new int[n]; for(int i=0;i<n;i++){ arr1[i] = read.nextInt(); } for(int i=0;i<n;i++){ arr2[i] = read.nextInt(); } Arrays.sort(arr1); Arrays.sort(arr2); boolean flag = true; for(int i=0;i<n;i++){ if(!(arr1[i]==arr2[i] || arr1[i]+1==arr2[i])) flag = false; } if(flag) System.out.println("YES"); else System.out.println("NO"); } read.close(); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
772c0a15acca07091467a8e23bbe59ad
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.*; import java.lang.Math; import java.lang.reflect.Array; import java.util.*; import javax.swing.text.DefaultStyledDocument.ElementSpec; public final class Solution { static BufferedReader br = new BufferedReader( new InputStreamReader(System.in) ); static BufferedWriter bw = new BufferedWriter( new OutputStreamWriter(System.out) ); static StringTokenizer st; /*write your constructor and global variables here*/ static class sortCond implements Comparator<Pair<Integer, Integer>> { @Override public int compare(Pair<Integer, Integer> p1, Pair<Integer, Integer> p2) { if (p1.a <= p2.a) { return -1; } else { return 1; } } } static class Rec { int a; int b; long c; Rec(int a, int b, long c) { this.a = a; this.b = b; this.c = c; } } static class Pair<f, s> { f a; s b; Pair(f a, s b) { this.a = a; this.b = b; } } interface modOperations { int mod(int a, int b, int mod); } static int findBinaryExponentian(int a, int pow, int mod) { if (pow == 1) { return a; } else if (pow == 0) { return 1; } else { int retVal = findBinaryExponentian(a, (int) pow / 2, mod); int val = (pow % 2 == 0) ? 1 : a; return modMul.mod(modMul.mod(retVal, retVal, mod), val, mod); } } static int findPow(int a, int b, int mod) { if (b == 1) { return a % mod; } else if (b == 0) { return 1; } else { int res = findPow(a, (int) b / 2, mod); return modMul.mod(res, modMul.mod(res, (b % 2 == 1 ? a : 1), mod), mod); } } static int bleft(long ele, ArrayList<Long> sortedArr) { int l = 0; int h = sortedArr.size() - 1; int ans = -1; while (l <= h) { int mid = l + (int) (h - l) / 2; if (sortedArr.get(mid) < ele) { l = mid + 1; } else if (sortedArr.get(mid) >= ele) { ans = mid; h = mid - 1; } } return ans; } static long gcd(long a, long b) { long div = b; long rem = a % b; while (rem != 0) { long temp = rem; rem = div % rem; div = temp; } return div; } static long[] log(long no, long n) { long i = 1l; long cnt = 0l; while (i < no) { i *= 2l; cnt++; } long arr[] = new long[2]; arr[0] = cnt; arr[1] = i; return arr; } static int log1(int no) { int i = 0; while ((1 << i) < no) { i++; } return (1 << i) == no ? (1 << i) : (1 << (i - 1)); } static modOperations modAdd = (int a, int b, int mod) -> { return (a % mod + b % mod) % mod; }; static modOperations modSub = (int a, int b, int mod) -> { return (int) ((1l * a % mod - 1l * b % mod + 1l * mod) % mod); }; static modOperations modMul = (int a, int b, int mod) -> { return (int) ((1l * (a % mod) * 1l * (b % mod)) % (1l * mod)); }; static modOperations modDiv = (int a, int b, int mod) -> { return modMul.mod(a, findBinaryExponentian(b, mod - 1, mod), mod); }; static HashSet<Integer> primeList(int MAXI) { int[] prime = new int[MAXI + 1]; HashSet<Integer> obj = new HashSet<>(); for (int i = 2; i <= (int) Math.sqrt(MAXI) + 1; i++) { if (prime[i] == 0) { obj.add(i); for (int j = i * i; j <= MAXI; j += i) { prime[j] = 1; } } } for (int i = (int) Math.sqrt(MAXI) + 1; i <= MAXI; i++) { if (prime[i] == 0) { obj.add(i); } } return obj; } static int[] factorialList(int MAXI, int mod) { int[] factorial = new int[MAXI + 1]; factorial[2] = 1; for (int i = 3; i < MAXI + 1; i++) { factorial[i] = modMul.mod(factorial[i - 1], i, mod); } return factorial; } static void put(HashMap<Integer, Integer> cnt, int key) { if (cnt.containsKey(key)) { cnt.replace(key, cnt.get(key) + 1); } else { cnt.put(key, 1); } } static long arrSum(ArrayList<Long> arr) { long tot = 0; for (int i = 0; i < arr.size(); i++) { tot += arr.get(i); } return tot; } static int ord(char b) { return (int) b - (int) 'a'; } static int optimSearch(int[] cnt, int lower_bound, int pow, int n) { int l = lower_bound + 1; int h = n; int ans = 0; while (l <= h) { int mid = l + (h - l) / 2; if (cnt[mid] - cnt[lower_bound] == pow) { return mid; } else if (cnt[mid] - cnt[lower_bound] < pow) { ans = mid; l = mid + 1; } else { h = mid - 1; } } return ans; } static Pair<Long, Integer> ret_ans(ArrayList<Integer> ans) { int size = ans.size(); int mini = 1000000000 + 1; long tit = 0l; for (int i = 0; i < size; i++) { tit += 1l * ans.get(i); mini = Math.min(mini, ans.get(i)); } return new Pair<>(tit - mini, mini); } static int factorList( HashMap<Integer, Integer> maps, int no, int maxK, int req ) { int i = 1; while (i * i <= no) { if (no % i == 0) { if (i != no / i) { put(maps, no / i); } put(maps, i); if (maps.get(i) == req) { maxK = Math.max(maxK, i); } if (maps.get(no / i) == req) { maxK = Math.max(maxK, no / i); } } i++; } return maxK; } static ArrayList<Integer> getKeys(HashMap<Integer, Integer> maps) { ArrayList<Integer> vals = new ArrayList<>(); for (Map.Entry<Integer, Integer> map : maps.entrySet()) { vals.add(map.getKey()); } return vals; } static ArrayList<Integer> getValues(HashMap<Integer, Integer> maps) { ArrayList<Integer> vals = new ArrayList<>(); for (Map.Entry<Integer, Integer> map : maps.entrySet()) { vals.add(map.getValue()); } return vals; } /*write your methods here*/ static int getMax(ArrayList<Integer> arr) { int max = arr.get(0); for (int i = 1; i < arr.size(); i++) { if (arr.get(i) > max) { max = arr.get(i); } } return max; } static int getMin(ArrayList<Integer> arr) { int max = arr.get(0); for (int i = 1; i < arr.size(); i++) { if (arr.get(i) < max) { max = arr.get(i); } } return max; } public static void main(String[] args) throws IOException { int cases = Integer.parseInt(br.readLine()), n, i, j; while (cases-- != 0) { n = Integer.parseInt(br.readLine()); int a[] = new int[n]; int b[] = new int[n]; st = new StringTokenizer(br.readLine()); for (i = 0; i < n; i++) { a[i] = Integer.parseInt(st.nextToken()); } st = new StringTokenizer(br.readLine()); for (i = 0; i < n; i++) { b[i] = Integer.parseInt(st.nextToken()); } Arrays.sort(a); Arrays.sort(b); boolean ok = true; for (i = 0; i < n; i++) { if (a[i] == b[i]) { continue; } else { if (a[i] > b[i]) { ok = false; break; } else { if (b[i] - a[i] == 1) { continue; } else { ok = false; break; } } } } if (ok) { bw.write("YES\n"); } else { bw.write("NO\n"); } } bw.flush(); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
55ee1d7d1e71333ca694ed730530df5a
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.*; import java.util.*; public class Q1584 { static int mod = (int) (1e9 + 7); static void solve() { int n = i(); long[] a = new long[n]; long[] b = new long[n]; for (int i = 0; i < n; i++) { a[i] = l(); } for (int i = 0; i < n; i++) { b[i] = l(); } Arrays.sort(a); Arrays.sort(b); for(int i=0;i<n;i++){ if(a[i]!=b[i] && a[i]+1!=b[i]){ System.out.println("NO"); return; } } System.out.println("YES"); } public static void main(String[] args) { int test = i(); while (test-- > 0) { solve(); } } // -----> POWER ---> long power(long x, long y) <---- power // -----> LCM ---> long lcm(long x, long y) <---- lcm // -----> GCD ---> long gcd(long x, long y) <---- gcd // -----> NCR ---> long ncr(int n, int r) <---- ncr // -----> (SORTING OF LONG, CHAR,INT) -->long[] sortLong(long[] a2)<-- // -----> (INPUT OF INT,LONG ,STRING) -> int i() long l() String s()<- // tempstart static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int Int() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String String() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return String(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static InputReader in = new InputReader(System.in); public static int i() { return in.Int(); } public static long l() { String s = in.String(); return Long.parseLong(s); } public static String s() { return in.String(); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
e199e459b96f3449fe88c1de1eb3f444
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class Main { static Scanner in = new Scanner(System.in); static int length; static int[] a; static int[] b; static int[] c; public static void main(String[] args) { int casesNumber = in.nextInt(); while (casesNumber-- != 0) { length = in.nextInt(); a = new int[length]; b = new int[length]; c = new int[length]; for (int i = 0; i < length; i++) a[i] = in.nextInt(); for (int i = 0; i < length; i++) { int n = in.nextInt(); b[i] = n; c[i] = n - 1; } Arrays.sort(a); Arrays.sort(b); Arrays.sort(c); System.out.println(result()); } } private static String result(){ for (int i = 0; i < length; i++) { if (a[i] != b[i] && a[i] != c[i]) return "NO"; } return "YES"; } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
803510bb21ed7170950723da22b5468a
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class test { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); int t = Integer.parseInt(br.readLine()); while (t-- > 0) { int n = Integer.parseInt(br.readLine()); StringTokenizer tokenizer = new StringTokenizer(br.readLine()); int[] a = new int[n]; int[] b = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(tokenizer.nextToken()); } tokenizer = new StringTokenizer(br.readLine()); for (int i = 0; i < n; i++) { b[i] = Integer.parseInt(tokenizer.nextToken()); } pw.println(solve(a, b, n)); } pw.flush(); pw.close(); br.close(); } public static String solve(int[] a, int[] b, int n) { Arrays.sort(a); Arrays.sort(b); for (int i = 0; i < n; i++) { if (a[i] != b[i] && a[i] + 1 != b[i]) { return "NO"; } } return "YES"; } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
887118e024905cc97f0fe7591da21bc7
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class TwoArrays { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int[] a=new int[n]; int[] b=new int[n]; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); } for(int i=0;i<n;i++) { b[i]=sc.nextInt(); } Arrays.sort(a); Arrays.sort(b); boolean ans=true; for(int i=0;i<n;i++) { if(a[i]!=b[i] && a[i]!=b[i]-1) { ans=false; } } System.out.println(ans?"YES":"NO"); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
02ae26d312c013fadf3ff95e08923f47
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
/*LoudSilence*/ import java.io.*; import java.util.*; import static java.lang.Math.*; public class Solution { /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ static FastScanner s = new FastScanner(); static FastWriter out = new FastWriter(); final static int mod = (int)1e9 + 7; final static int INT_MAX = Integer.MAX_VALUE; final static int INT_MIN = Integer.MIN_VALUE; final static long LONG_MAX = Long.MAX_VALUE; final static long LONG_MIN = Long.MIN_VALUE; final static double DOUBLE_MAX = Double.MAX_VALUE; final static double DOUBLE_MIN = Double.MIN_VALUE; final static float FLOAT_MAX = Float.MAX_VALUE; final static float FLOAT_MIN = Float.MIN_VALUE; /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ static class FastScanner{BufferedReader br;StringTokenizer st; public FastScanner() {if(System.getProperty("ONLINE_JUDGE") == null){try {br = new BufferedReader(new FileReader("E:\\Competitive Coding\\input.txt"));} catch (FileNotFoundException e) {br = new BufferedReader(new InputStreamReader(System.in));}}else{br = new BufferedReader(new InputStreamReader(System.in));}} String next(){while (st == null || !st.hasMoreElements()){try{st = new StringTokenizer(br.readLine());}catch (IOException e){e.printStackTrace();}}return st.nextToken();} int nextInt(){return Integer.parseInt(next());} long nextLong(){return Long.parseLong(next());} double nextDouble(){return Double.parseDouble(next());} List<Integer> readIntList(int n){List<Integer> arr = new ArrayList<>(); for(int i = 0; i < n; i++) arr.add(s.nextInt()); return arr;} List<Long> readLongList(int n){List<Long> arr = new ArrayList<>(); for(int i = 0; i < n; i++) arr.add(s.nextLong()); return arr;} int[] readIntArr(int n){int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = s.nextInt(); return arr;} long[] readLongArr(int n){long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = s.nextLong(); return arr;} String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}} static class FastWriter{private BufferedWriter bw;public FastWriter(){if(System.getProperty("ONLINE_JUDGE") == null){try {this.bw = new BufferedWriter(new FileWriter("E:\\Competitive Coding\\output.txt"));} catch (IOException e) {this.bw = new BufferedWriter(new OutputStreamWriter(System.out));}}else{this.bw = new BufferedWriter(new OutputStreamWriter(System.out));}} public void print(Object object) throws IOException{bw.append(""+ object);} public void println(Object object) throws IOException{print(object);bw.append("\n");} public void debug(int object[]) throws IOException{bw.append("["); for(int i = 0; i < object.length; i++){if(i != object.length-1){print(object[i]+", ");}else{print(object[i]);}}bw.append("]\n");} public void debug(long object[]) throws IOException{bw.append("["); for(int i = 0; i < object.length; i++){if(i != object.length-1){print(object[i]+", ");}else{print(object[i]);}}bw.append("]\n");} public void close() throws IOException{bw.close();}} public static void println(Object str) throws IOException{out.println(""+str);} public static void println(Object str, int nextLine) throws IOException{out.print(""+str);} /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ public static ArrayList<Integer> seive(int n){ArrayList<Integer> list = new ArrayList<>();int arr[] = new int[n+1];for(long i = 2; i <= n; i++) {if(arr[(int)i] == 1) {continue;}else {list.add((int)i);for(long j = i*i; j <= n; j = j + i) {arr[(int)j] = 1;}}}return list;} public static long gcd(long a, long b){if(a > b) {a = (a+b)-(b=a);}if(a == 0L){return b;}return gcd(b%a, a);} public static void swap(int[] arr, int i, int j) {arr[i] = arr[i] ^ arr[j]; arr[j] = arr[j] ^ arr[i]; arr[i] = arr[i] ^ arr[j];} public static boolean isPrime(long n){if(n < 2){return false;}if(n == 2 || n == 3){return true;}if(n%2 == 0 || n%3 == 0){return false;}long sqrtN = (long)Math.sqrt(n)+1;for(long i = 6L; i <= sqrtN; i += 6) {if(n%(i-1) == 0 || n%(i+1) == 0) return false;}return true;} public static long mod_add(long a, long b){ return (a%mod + b%mod)%mod;} public static long mod_sub(long a, long b){ return (a%mod - b%mod + mod)%mod;} public static long mod_mul(long a, long b){ return (a%mod * b%mod)%mod;} public static long modInv(long a, long b){ return expo(a, b-2)%b;} public static long mod_div(long a, long b){return mod_mul(a, modInv(b, mod));} public static long expo (long a, long n){if(n == 0){return 1;}long recAns = expo(mod_mul(a,a), n/2);if(n % 2 == 0){return recAns;}else{return mod_mul(a, recAns);}} /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ // Pair class public static class Pair<X extends Comparable<X>,Y extends Comparable<Y>> implements Comparable<Pair<X, Y>>{ X first; Y second; public Pair(X first, Y second){ this.first = first; this.second = second; } public String toString(){ return "( " + first+" , "+second+" )"; } @Override public int compareTo(Pair<X, Y> o) { int t = first.compareTo(o.first); if(t == 0) return second.compareTo(o.second); return t; } } /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ // Code begins public static void solve() throws IOException { int n = s.nextInt(); List<Integer> a = s.readIntList(n); List<Integer> b = s.readIntList(n); Collections.sort(a); Collections.sort(b); for(int i = 0; i < n; i++){ int diff = b.get(i) - a.get(i); if(diff > 1 || diff < 0){ println("NO"); return; } } println("YES"); } /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ public static void main(String[] args) throws IOException { int test = s.nextInt(); for(int t = 1; t <= test; t++) { solve(); } out.close(); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
a84da316126c88dbd74548d48a9e1f3b
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.util.*; import java.io.*; import java.math.*; public class C_Two_Arrays { public static void main(String[] args) { OutputStream outputStream = System.out; PrintWriter out = new PrintWriter(outputStream); FastReader f = new FastReader(); int t = f.nextInt(); while(t-- > 0){ solve(f, out); } out.close(); } public static void solve(FastReader f, PrintWriter out) { int n = f.nextInt(); int a[] = new int[n]; for(int i = 0; i < n; i++) { a[i] = f.nextInt(); } int b[] = new int[n]; for(int i = 0; i < n; i++) { b[i] = f.nextInt(); } sort(a); sort(b); for(int i = 0; i < n; i++) { if(a[i] == b[i] || b[i] == a[i]+1) { } else { out.println("NO"); return; } } out.println("YES"); } public static void sort(int arr[]) { ArrayList<Integer> al = new ArrayList<>(); for(int i: arr) { al.add(i); } Collections.sort(al); for(int i = 0; i < arr.length; i++) { arr[i] = al.get(i); } } public static void allDivisors(int n) { for(int i = 1; i*i <= n; i++) { if(n%i == 0) { System.out.println(i + " "); if(i != n/i) { System.out.println(n/i + " "); } } } } public static boolean isPrime(int n) { if(n < 1) return false; if(n == 2 || n == 3) return true; if(n % 2 == 0 || n % 3 == 0) return false; for(int i = 5; i*i <= n; i += 6) { if(n % i == 0 || n % (i+2) == 0) { return false; } } return true; } public static int gcd(int a, int b) { int dividend = a > b ? a : b; int divisor = a < b ? a : b; while(divisor > 0) { int reminder = dividend % divisor; dividend = divisor; divisor = reminder; } return dividend; } public static int lcm(int a, int b) { int lcm = gcd(a, b); int hcf = (a * b) / lcm; return hcf; } public static String sortString(String inputString) { char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } float nextFloat() { return Float.parseFloat(next()); } boolean nextBoolean() { return Boolean.parseBoolean(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } /** Dec Char Dec Char Dec Char Dec Char --------- --------- --------- ---------- 0 NUL (null) 32 SPACE 64 @ 96 ` 1 SOH (start of heading) 33 ! 65 A 97 a 2 STX (start of text) 34 " 66 B 98 b 3 ETX (end of text) 35 # 67 C 99 c 4 EOT (end of transmission) 36 $ 68 D 100 d 5 ENQ (enquiry) 37 % 69 E 101 e 6 ACK (acknowledge) 38 & 70 F 102 f 7 BEL (bell) 39 ' 71 G 103 g 8 BS (backspace) 40 ( 72 H 104 h 9 TAB (horizontal tab) 41 ) 73 I 105 i 10 LF (NL line feed, new line) 42 * 74 J 106 j 11 VT (vertical tab) 43 + 75 K 107 k 12 FF (NP form feed, new page) 44 , 76 L 108 l 13 CR (carriage return) 45 - 77 M 109 m 14 SO (shift out) 46 . 78 N 110 n 15 SI (shift in) 47 / 79 O 111 o 16 DLE (data link escape) 48 0 80 P 112 p 17 DC1 (device control 1) 49 1 81 Q 113 q 18 DC2 (device control 2) 50 2 82 R 114 r 19 DC3 (device control 3) 51 3 83 S 115 s 20 DC4 (device control 4) 52 4 84 T 116 t 21 NAK (negative acknowledge) 53 5 85 U 117 u 22 SYN (synchronous idle) 54 6 86 V 118 v 23 ETB (end of trans. block) 55 7 87 W 119 w 24 CAN (cancel) 56 8 88 X 120 x 25 EM (end of medium) 57 9 89 Y 121 y 26 SUB (substitute) 58 : 90 Z 122 z 27 ESC (escape) 59 ; 91 [ 123 { 28 FS (file separator) 60 < 92 \ 124 | 29 GS (group separator) 61 = 93 ] 125 } 30 RS (record separator) 62 > 94 ^ 126 ~ 31 US (unit separator) 63 ? 95 _ 127 DEL */
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
f66d7080ec4434e2f5b89ab2d5f1215a
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class ddz { public static void main(String[] args) { System.out.println(); Scanner sc = new Scanner(System.in); int x= sc.nextInt(); while(x-->0) { int n=sc.nextInt(); int[] a=new int[n]; int[] b=new int[n]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } for(int i=0;i<n;i++){ b[i]=sc.nextInt(); } Arrays.sort(a); Arrays.sort(b); boolean flag=true; for(int i=0;i<n;i++){ if(a[i]+1==b[i] || a[i]==b[i]) continue; flag=false; } if(flag) System.out.println("YES"); else System.out.println("NO"); } sc.close(); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
9df7ce843409c365e5af81dac1c89a21
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int t = scn.nextInt(); while(t-->0){ int n = scn.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for(int i = 0; i<n; i++){ a[i] = scn.nextInt(); } for(int i = 0; i<n; i++){ b[i] = scn.nextInt(); } Arrays.sort(a); Arrays.sort(b); boolean flag = true; for(int i = 0; i<n; i++){ if(a[i] != b[i]){ if(a[i] + 1 != b[i]){ flag = false; break; } } } if(flag) System.out.println("yes"); else System.out.println("no"); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
12849914a32744c1887575c88d77ac89
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class TwoArrays{ public static void main(String[] args)throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int testCases = Integer.parseInt(br.readLine()); StringBuilder result = new StringBuilder(); StringTokenizer str; while(testCases-- > 0){ int n = Integer.parseInt(br.readLine()); str = new StringTokenizer(br.readLine()); int a[] = new int[n]; for(int i = 0; i < n; i++){ a[i] = Integer.parseInt(str.nextToken()); } str = new StringTokenizer(br.readLine()); int b[] = new int[n]; for(int i = 0; i < n; i++){ b[i] = Integer.parseInt(str.nextToken()); } Arrays.sort(a); Arrays.sort(b); boolean flag = true; int count = 0; for(int i = 0; i < n; i++){ if(a[i] != b[i]){ if((a[i] + 1) != b[i]){ flag = false; break; } } } if(flag){ result.append("YES\n"); }else{ result.append("NO\n"); } } System.out.println(result); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
86daf232253b5d5d05744f47b74ba27e
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); // long mod = 1_000_000_007L; // long mod = 998_244_353L; int t = sc.nextInt(); for ( int zzz=0; zzz<t; zzz++ ) { int n = sc.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for ( int i=0; i<n; i++ ) { a[i] = sc.nextInt(); } Arrays.sort(a); for ( int i=0; i<n; i++ ) { b[i] = sc.nextInt(); } Arrays.sort(b); String ans="Yes"; for(int i=0;i<n;i++) { if(b[i]-a[i]==0 || b[i]-a[i]==1) continue; else { ans="No"; break; } } System.out.println(ans); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
bef67997837829cfc11cd6502ab6dd5b
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; import java.io.*; public class CP { static final int MOD = (int) (1e9) + 7;// ((a + b) % MOD + MOD) % MOD public static void main(String[] args) throws IOException { FastReader sc = new FastReader(); int t = sc.Int(); for (; t > 0; t--) { int n = sc.Int(); int a[] = new int[n]; int b[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.Int(); } for (int i = 0; i < n; i++) { b[i] = sc.Int(); } Arrays.sort(a); Arrays.sort(b); boolean sts = true; for (int i = 0; i < n; i++) { if (b[i] - a[i] != 0 && b[i] - a[i] != 1) { sts = false; break; } } System.out.println(sts ? "YES" : "NO"); } sc.close(); } } class FastReader { private BufferedReader br; private StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public String next() throws IOException { for (; st == null || !st.hasMoreTokens();) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } public String nextLine() throws IOException { return br.readLine(); } public int Int() throws IOException { return Integer.parseInt(next()); } public long Long() throws IOException { return Long.parseLong(next()); } public double Double() throws IOException { return Double.parseDouble(next()); } public float Float() throws IOException { return Float.parseFloat(next()); } public char Char() throws IOException { return next().charAt(0); } public void close() throws IOException { br.close(); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
3f07341a9f8d5abe9223b0ffa05e1764
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.Arrays; import java.util.Scanner; /** * * @author eslam */ public class TwoArrays2 { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input = new Scanner(System.in); int t = input.nextInt(); loop:while(t-->0){ int n = input.nextInt(); int a[] = new int[n]; int b[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = input.nextInt(); } for (int i = 0; i < n; i++) { b[i] = input.nextInt(); } Arrays.sort(a); Arrays.sort(b); for (int i = 0; i < n; i++) { if(a[i]!=b[i]){ int x = b[i]-a[i]; if(x!=1&&x!=0){ System.out.println("NO"); continue loop; } } } System.out.println("YES"); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
e07d1490e40c061bde253da51ec4faa2
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int a[] = new int[n]; int b[] = new int[n]; for(int i = 0; i<n; i++) a[i] = sc.nextInt(); for(int i = 0; i<n; i++) b[i] = sc.nextInt(); Arrays.sort(b); Arrays.sort(a); boolean isPossible = true; for(int i = 0; i< n; i++){ if((b[i]-a[i])!=0 && (b[i]-a[i])!=1){ isPossible = false; } } System.out.println(isPossible?"Yes":"No"); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
eb3ad61b05aab21452f68268e610c85d
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
//package com.codeforces.Practise; import java.io.*; import java.util.Arrays; public class TwoArrays { //Don't Confuse Always make things simple //Experience is the name of the game // You won't fail until you stop trying....... // you can solve one problem by many approaches. when you stuck you are going to learn something new okk // Everything is easy. you feel its hard because of you don't know, and you not understand it very well. //// How to Improve Your problem-solving skill ??( By practise ). ***simple /// ==>> Solve problems slightly above of your level (to know some logic and how to approach cp problems) // Otherwise You will stay as it is okk. Learn from other code as well. ///////////////////////////////////////////////////////////////////////// /// How to Solve Problem in CP ? (you need to come up with brainstorm) ( if you feel problem is hard then your approach is wrong ) // ==>> Step01 :- Understanding problem statement clearly. Then Only Move Forward (Because Everything is mentioned in problem statement). // Step02 :- Think a lot about Solution. if you are confident that your solution might be correct Then only Move Forward // Step03 :- First think of brute force then move to optimal approach // Step04 :- Finally Code ( there is no any sense to code. if you not follow about steps okk) /////////////////////////////////////////////////////////////////////////// public static void main(String[] args)throws IOException { Reader scan=new Reader(); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int t=scan.nextInt(); while (t-->0) { int n=scan.nextInt(); int[] a=new int[n]; int[] b=new int[n]; for (int i = 0; i < n; i++) { a[i]=scan.nextInt(); } for (int i = 0; i < n; i++) { b[i]=scan.nextInt(); } Arrays.sort(a); Arrays.sort(b); boolean flag=true; for (int i = 0; i < n; i++) { if(a[i]==b[i]){ continue; } else if(a[i]+1==b[i]){ continue; } else { flag=false; break; } } if(flag){ bw.write("YES"); } else { bw.write("NO"); } bw.newLine(); bw.flush(); } } //FAST READER static class Reader { public int BS = 1<<16; public char NC = (char)0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public Reader() { in = new BufferedInputStream(System.in, BS); } public Reader(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar(){ while(bId==size) { try { size = in.read(buf); }catch(Exception e) { return NC; } if(size==-1)return NC; bId=0; } return (char)buf[bId++]; } public int nextInt() { return (int)nextLong(); } public long nextLong() { num=1; boolean neg = false; if(c==NC)c=nextChar(); for(;(c<'0' || c>'9'); c = nextChar()) { if(c=='-')neg=true; } long res = 0; for(; c>='0' && c <='9'; c=nextChar()) { res = (res<<3)+(res<<1)+c-'0'; num*=10; } return neg?-res:res; } public double nextDouble() { double cur = nextLong(); return c!='.' ? cur:cur+(cur < 0 ? -1*nextLong()/num : nextLong()/num); } public String next() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c>32) { res.append(c); c=nextChar(); } return res.toString(); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
d1a9cdfbd726f27a79ab17991b1fd44e
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class TwoArrays { public static void main(String args[]) { int i,j,k,t,n; Scanner sc=new Scanner(System.in); t=sc.nextInt(); while(t-->0) { n=sc.nextInt(); int a[]=new int[n]; int b[]=new int[n]; for(i=0;i<n;i++) { a[i]=sc.nextInt(); } for(i=0;i<n;i++) { b[i]=sc.nextInt(); } Arrays.sort(a); Arrays.sort(b); int flag=0; for(i=0;i<n;i++) { if(a[i]>b[i]) { flag=1; break; } if(a[i]==b[i]||(a[i]+1)==b[i]) { continue; } else { flag=1; break; } } if(flag==1) { System.out.println("NO"); } else { System.out.println("YES"); } } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
039c308ac0d45eb62be3e37b877e62f4
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int tt=sc.nextInt(); while(tt-->0) { int n=sc.nextInt(); int[] a=new int[n]; for(int i=0;i<n;i++) a[i]=sc.nextInt(); int[] b=new int[n]; for(int i=0;i<n;i++) b[i]=sc.nextInt(); boolean flag=true; Arrays.sort(a); Arrays.sort(b); for(int i=0;i<n;i++) { if(a[i]!=b[i]) { if(a[i]+1!=b[i]){ flag=false; break; } } } if(flag)System.out.println("YES"); else System.out.println("NO"); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
df8b8263ae32c6799bd4d5d340887ee1
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Manav */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); CTwoArrays solver = new CTwoArrays(); solver.solve(1, in, out); out.close(); } static class CTwoArrays { public void solve(int testNumber, InputReader in, OutputWriter out) { int t = in.nextInt(); for (int it = 0; it < t; it++) { int n = in.nextInt(); Integer[] a = new Integer[n], b = new Integer[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } for (int i = 0; i < n; i++) { b[i] = in.nextInt(); } Arrays.sort(a); Arrays.sort(b); boolean hasAns = true; for (int i = 0; i < n; i++) { if (b[i] - a[i] <= 1 && b[i] - a[i] >= 0) continue; hasAns = false; break; } if (hasAns) out.println("YES"); else out.println("NO"); } } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
4b984c623c6716fdb045e74947434919
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.Arrays; import java.util.Scanner; import java.util.stream.IntStream; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int tc = 0; tc < t; ++tc) { int n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < a.length; ++i) { a[i] = sc.nextInt(); } int[] b = new int[n]; for (int i = 0; i < b.length; ++i) { b[i] = sc.nextInt(); } System.out.println(solve(a, b) ? "YES" : "NO"); } sc.close(); } static boolean solve(int[] a, int[] b) { Arrays.sort(a); Arrays.sort(b); return IntStream.range(0, a.length).allMatch(i -> a[i] == b[i] || a[i] + 1 == b[i]); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
e2753d6e1ad059497c43abfd6447cb92
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.Scanner; import java.util.Arrays; public class Main{ public static void main(String[] args){ Scanner scn = new Scanner(System.in); int t = scn.nextInt(); for(int k=0;k<t;k++){ int n = scn.nextInt(); int[] a = new int[n]; for(int i=0;i<n;i++){ a[i]=scn.nextInt(); } int[] b = new int[n]; for(int i=0;i<n;i++){ b[i]=scn.nextInt(); } Arrays.sort(a); Arrays.sort(b); for(int i=0;i<n;i++){ if(a[i]!=b[i]&&(a[i]+1)!=b[i]){ System.out.println("NO"); break; } if(i==n-1){ System.out.println("YES"); } } } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
4a443f9a63c875cf745d2fbd36d6f636
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.Arrays; public class NewTemplate { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) throws IOException{ FastReader Scanner = new FastReader(); // FOR GETTING THE TEST CASES int testCases = Scanner.nextInt(); while(testCases-- > 0){ //solve(); int n = Scanner.nextInt(); int[] a = new int[n], b = new int[n]; for(int i = 0; i < n; i++) { a[i] = Scanner.nextInt(); } for(int i = 0; i < n; i++) { b[i] = Scanner.nextInt(); } Arrays.sort(a); Arrays.sort(b); boolean faulty = false; for(int i = 0;i < n; i++) { if(b[i] - a[i] != 1 && b[i] -a[i] != 0) { System.out.println("NO"); faulty = true; break; } } if(!faulty) System.out.println("YES"); } } private static void PrintArr(int[] array){ for(int i : array){ System.out.print(i + " "); } System.out.println(); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
5688316b2b894e095e0aa0dd27ba450b
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; import java.lang.*; public class C_Two_Arrays{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int a[]=new int[n]; int b[]=new int[n]; for(int i=0;i<n;i++) a[i]=sc.nextInt(); for(int i=0;i<n;i++) b[i]=sc.nextInt(); Arrays.sort(a); Arrays.sort(b); boolean flag=true; for(int i=0;i<n;i++){ // System.out.println("Diff:"+(b[i]-a[i])); if((b[i]-a[i])==1 || (b[i]-a[i])==0){ continue; }else{ // System.out.println("Broke"); flag=false; break; } } if(flag==true) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
79b10305d7fd2666e9e45688a3460cf6
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.util.Arrays; public class TwoArrays { private static String solve(int n, int a[], int b[]) { Arrays.sort(a); Arrays.sort(b); for (int i = 0 ; i < n ; i++) { int val = b[i] - a[i]; if (val == 0) continue; if ( val!= 1) return "NO"; } return "YES"; } public static void main(String[] args) throws IOException { Scanner s = new Scanner(); int t = 1; t = s.nextInt(); StringBuilder ans = new StringBuilder(); int count = 0; while (t-- > 0) { int n = s.nextInt(); int a[] = new int[n]; int b[] = new int[n]; getInputs(s,a,n); getInputs(s,b,n); ans.append(solve(n, a, b)).append("\n"); } System.out.println(ans.toString()); } static class Scanner { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Scanner() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Scanner(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } public static long norm(long a, long MOD) { return ((a % MOD) + MOD) % MOD; } public static long msub(long a, long b, long MOD) { return norm(norm(a, MOD) - norm(b, MOD), MOD); } public static long madd(long a, long b, long MOD) { return norm(norm(a, MOD) + norm(b, MOD), MOD); } public static long mMul(long a, long b, long MOD) { return norm(norm(a, MOD) * norm(b, MOD), MOD); } public static long mDiv(long a, long b, long MOD) { return norm(norm(a, MOD) / norm(b, MOD), MOD); } public static String formattedArray(int a[]) { StringBuilder res = new StringBuilder(""); for (int e : a) res.append(e).append(" "); return res.toString().trim(); } private static long getLong(Scanner s) throws IOException { return s.nextLong(); } private static int getInt(Scanner s) throws IOException { return s.nextInt(); } private static void getInputs(Scanner s, int[] a, int n) throws IOException { for (int i = 0; i < n; i++) { a[i] = s.nextInt(); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
8abf9666d7cc7011cab638ffbe6e92cd
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; import java.io.*; public class Check1{ static FastReader in = new FastReader(); static final Random random = new Random(); static long mod = 1000000007L; static HashMap<String, Integer> map = new HashMap<>(); public static void main(String[] args) { int t=in.nextInt(); while(t-->0) { int n=in.nextInt(); boolean flag=true; int []a=new int[n]; int []b=new int[n]; for(int i=0;i<n;i++) { a[i]=in.nextInt(); } for(int i=0;i<n;i++) { b[i]=in.nextInt(); } ruffleSort(a); ruffleSort(b); for(int i=0;i<n;i++) { if((a[i]<b[i]&&(a[i]!=b[i]-1))||a[i]>b[i]) { flag=false; break; } } System.out.println(flag==true?"YES":"NO"); } } static int max(int a, int b) { if (a < b) return b; return a; } static void ruffleSort(int[] a) { int n = a.length; for (int i = 0; i < n; i++) { int oi = random.nextInt(n), temp = a[oi]; a[oi] = a[i]; a[i] = temp; } Arrays.sort(a); } static <E> void print(E res) { System.out.println(res); } static int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static int abs(int a) { if (a < 0) return -1 * a; return a; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readintarray(int n) { int res[] = new int[n]; for (int i = 0; i < n; i++) res[i] = nextInt(); return res; } long[] readlongarray(int n) { long res[] = new long[n]; for (int i = 0; i < n; i++) res[i] = nextLong(); return res; } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
b0eec404b7ed6870905bacfe13bd8f7f
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.Scanner; import java.util.Arrays; public class TwoArrays { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t > 0) { int n = sc.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for(int i = 0; i < n; i++) { a[i] = sc.nextInt(); } for(int i = 0; i < n; i++) { b[i] = sc.nextInt(); } Arrays.sort(a); Arrays.sort(b); boolean possible = true; for(int i = 0; i < n; i++) { if(b[i] != a[i] && b[i] != 1 + a[i]) { possible = false; break; } } if(possible) { System.out.println("YES"); } else { System.out.println("NO"); } t--; } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
746c1bae60c41d9196f822b2d2166c7f
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class Solution{ static Scanner sc = new Scanner(System.in); public static void main(String[] a) { int testCases = sc.nextInt(); long t1 = System.currentTimeMillis(); for(int i=1; i<=testCases; i++){ solve(); } if (System.getProperty("ONLINE_JUDGE") == null){ long t2 = System.currentTimeMillis(); System.err.println("Time = " + (t2 - t1)); } } public static void solve(){ int n=sc.nextInt(); int[] a =new int[n]; int[] b =new int[n]; for(int i=0;i<n;i++){ a[i] = (sc.nextInt()); } for(int i=0;i<n;i++) { b[i] = (sc.nextInt()); } Arrays.sort(a); Arrays.sort(b); n--; while(n>=0){ if(b[n]-a[n] == 1 || b[n]-a[n] == 0){ n--; }else{ System.out.println("NO"); return; } } System.out.println("YES"); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
deb79cecd444a23eabd16a4294c6e8b7
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.*; import java.util.*; public class MyClass { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); while(t-->0){ int n=Integer.parseInt(br.readLine()); String s1[]=br.readLine().split(" "); String s2[]=br.readLine().split(" "); int a[]=new int[n]; int b[]=new int[n]; for(int i=0;i<n;i++){ a[i]=Integer.parseInt(s1[i]); b[i]=Integer.parseInt(s2[i]); } Arrays.sort(a); Arrays.sort(b); boolean f=true; for(int i=0;i<n;i++){ if(a[i]==b[i]||a[i]+1==b[i]){ continue; } f=false; break; } if(f) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
a238d1a5fa291b5bc28dc3bc0f062bd3
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0){ int n = sc.nextInt(); int [] a = new int[n]; int [] b = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { b[i] = sc.nextInt(); } Arrays.sort(a); Arrays.sort(b); int i = 0; for (; i < b.length; i++) { if(a[i]==b[i] || a[i]+1==b[i])continue; else{ System.out.println("NO"); break; } } if(i==b.length)System.out.println("YES"); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
2162c7534443db076dd4f74e75df5696
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.*; import java.util.Arrays; public class TwoArrays { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); for(int k = 0; k < t; k++) { int n = Integer.parseInt(br.readLine()); String num[] = br.readLine().split(" "); int a[] = new int[n]; int b[] = new int[n]; for(int i = 0; i < n; i++) a[i] = Integer.parseInt(num[i]); num = br.readLine().split(" "); for(int i = 0; i < n; i++) b[i] = Integer.parseInt(num[i]); Arrays.sort(a); Arrays.sort(b); int flag = 1; for(int i = n - 1; i >= 0; i--) if((a[i] > b[i]) || (b[i] - a[i] > 1)) { flag = 0; break; } if(flag == 0) System.out.println("NO"); else System.out.println("YES"); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
de83fc01825c9c3660525a9b2faad485
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
//package currentContest; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Random; import java.util.Scanner; import java.util.StringTokenizer; public class P1 { public static void main(String[] args) { // TODO Auto-generated method stub FastReader sc = new FastReader(); int t; t = sc.nextInt(); StringBuilder st = new StringBuilder(); int tc=1; while (t-- != 0) { int n=sc.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); } int b[]=new int[n]; for(int i=0;i<n;i++) { b[i]=sc.nextInt(); } sort(a); sort(b); int flag=0; for(int i=0;i<n;i++) { if(b[i]-a[i]==1||b[i]-a[i]==0) continue; flag=1; } if(flag==0) { st.append("YES\n"); }else { st.append("NO\n"); } } System.out.println(st); } static FastReader sc = new FastReader(); public static void solvegraph() { int n = sc.nextInt(); int edge[][] = new int[n - 1][2]; for (int i = 0; i < n - 1; i++) { edge[i][0] = sc.nextInt() - 1; edge[i][1] = sc.nextInt() - 1; } ArrayList<ArrayList<Integer>> ad = new ArrayList<>(); for (int i = 0; i < n; i++) { ad.add(new ArrayList<Integer>()); } for (int i = 0; i < n - 1; i++) { ad.get(edge[i][0]).add(edge[i][1]); ad.get(edge[i][1]).add(edge[i][0]); } int parent[] = new int[n]; Arrays.fill(parent, -1); parent[0] = n; ArrayDeque<Integer> queue = new ArrayDeque<>(); queue.add(0); int child[] = new int[n]; Arrays.fill(child, 0); ArrayList<Integer> lv = new ArrayList<Integer>(); while (!queue.isEmpty()) { int toget = queue.getFirst(); queue.removeFirst(); child[toget] = ad.get(toget).size() - 1; for (int i = 0; i < ad.get(toget).size(); i++) { if (parent[ad.get(toget).get(i)] == -1) { parent[ad.get(toget).get(i)] = toget; queue.addLast(ad.get(toget).get(i)); } } lv.add(toget); } child[0]++; } static void sort(int[] A) { int n = A.length; Random rnd = new Random(); for (int i = 0; i < n; ++i) { int tmp = A[i]; int randomPos = i + rnd.nextInt(n - i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } static void sort(long[] A) { int n = A.length; Random rnd = new Random(); for (int i = 0; i < n; ++i) { long tmp = A[i]; int randomPos = i + rnd.nextInt(n - i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } static String sort(String s) { Character ch[] = new Character[s.length()]; for (int i = 0; i < s.length(); i++) { ch[i] = s.charAt(i); } Arrays.sort(ch); StringBuffer st = new StringBuffer(""); for (int i = 0; i < s.length(); i++) { st.append(ch[i]); } return st.toString(); } public static long gcd(long a, long b) { if (a == 0) { return b; } return gcd(b % a, a); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
e2dce67b34cc0c2ee0fc7b687b96a497
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Test { static FastScanner sc = new FastScanner(); static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); public static void main(String[] args) { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] arr1 = new int[n]; int[] arr2 = new int[n]; for (int i = 0; i < n; i++) { arr1[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { arr2[i] = sc.nextInt(); } Arrays.sort(arr1); Arrays.sort(arr2); boolean check = true; for (int i = 0; i < n; i++) { int dif = arr1[i] - arr2[i]; if (dif > 0 || dif < -1) { System.out.println("NO"); check = false; break; } } if (check) { System.out.println("YES"); } } } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
0cac04dcf0f3fb8cb63b0d4162fa7aa5
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Codeforces { static long mod = 1_000_000__007; public static void main(String[] args) { FastReader fastReader = new FastReader(); int t = fastReader.nextInt(); while(t-->0){ int n = fastReader.nextInt(); int []a1 = new int[n]; int []a2= new int[n]; for (int i = 0 ; i< n ; i++){ a1[i] = fastReader.nextInt(); } for (int i = 0 ; i< n ; i++){ a2[i] = fastReader.nextInt(); } Arrays.sort(a1); Arrays.sort(a2); boolean isValid = true; for (int i=0; i < n ; i++){ if (a1[i] != a2[i] && (a1[i]+1) != a2[i]){ isValid =false; break; } } if (isValid){ System.out.println("YES"); }else{ System.out.println("NO"); } } } public static boolean isEqual(String s1, String s2) { boolean isValid = true; if (s1.length() != s2.length()) { return false; } for (int i = 0; i < s1.length(); i++) { if (s1.charAt(i) != s2.charAt(i)) { isValid = false; break; } } return isValid; } static long power(long a, long b) { if (a == 1 || b == 0) { return 1L; } long res = 1; while (b != 0) { if (b % 2 == 1) { res = (res * a) % mod; } b /= 2; a = (a * a) % mod; } return res % mod; } static class Pair { int x; int y; Pair(int x, int y) { this.x = x; this.y = y; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
d845100a541eb5f7f44d66859a01abc2
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.Locale; import java.util.StringTokenizer; public class C { private void solve() { int t = readInt(); for (int l = 0; l < t; l++) { int n = readInt(); int[] first = readIntArray(n); int[] second = readIntArray(n); int[] sortedFirst = Arrays.copyOf(first, n); int[] sortedSecond = Arrays.copyOf(second, n); Arrays.sort(sortedFirst); Arrays.sort(sortedSecond); boolean res = true; for (int i = 0; i < n; i++) { if (sortedFirst[i] == sortedSecond[i] || sortedFirst[i] == sortedSecond[i] - 1) { } else { res = false; break; } } yesNo(res); } } ////////////////////////////////////////////////////////////////// long sqrtLong(long x) { long root = (long)Math.sqrt(x); while (root * root > x) --root; while ((root + 1) * (root + 1) <= x) ++root; return root; } ////////////////////////////////////////////////////////////////// private boolean yesNo(boolean yes) { return yesNo(yes, "YES", "NO"); } private boolean yesNo(boolean yes, String yesString, String noString) { out.println(yes ? yesString : noString); return yes; } ////////////////////////////////////////////////////////////////// private long readLong() { return Long.parseLong(readString()); } private int[] readIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; ++i) a[i] = readInt(); return a; } private int readInt() { return Integer.parseInt(readString()); } private String readString() { while (!tok.hasMoreTokens()) { String nextLine = readLine(); if (null == nextLine) return null; tok = new StringTokenizer(nextLine); } return tok.nextToken(); } private String readLine() { try { return in.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } ////////////////////////////////////////////////////////////////// private BufferedReader in; private StringTokenizer tok; private PrintWriter out; private void initFileIO(String inputFileName, String outputFileName) throws FileNotFoundException { in = new BufferedReader(new FileReader(inputFileName)); out = new PrintWriter(outputFileName); } private void initConsoleIO() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } private void initIO() throws IOException { Locale.setDefault(Locale.US); String fileName = ""; if (!fileName.isEmpty()) { initFileIO(fileName + ".in", fileName + ".out"); } else { if (new File("input.txt").exists()) { initFileIO("input.txt", "output.txt"); } else { initConsoleIO(); } } tok = new StringTokenizer(""); } ////////////////////////////////////////////////////////////////// private void run() { try { long timeStart = System.currentTimeMillis(); initIO(); solve(); out.close(); long timeEnd = System.currentTimeMillis(); System.err.println("Time(ms) = " + (timeEnd - timeStart)); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } public static void main(String[] args) { new C().run(); } ///////////////////////////////////////////////////////////////// private static boolean isPrime(int input) { if (input % 2 == 0) return input == 2; int d = 3; while (d * d < Math.sqrt(input) + 1) { if (input % d == 0) return false; d += 2; } return true; } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
5a7149f361a68391d08ceaf4eccae98f
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.Scanner; public class C{ static Scanner scan; public static void main(String[] args){ scan = new Scanner(System.in); int t = scan.nextInt(); for(int i = 0; i< t; i++){ raschet(); } } private static void raschet(){ int n = scan.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for(int i = 0; i< n; i++){ a[i] = scan.nextInt(); } for(int i = 0; i< n; i++){ b[i] = scan.nextInt(); } sort(a); sort(b); boolean result = true; for(int i = 0; i< n; i++){ int d = b[i]-a[i]; //System.out.println( if(d<0 || d>1){ result = false; break; } } if(result){ System.out.println("YES"); }else{ System.out.println("NO"); } } private static void sort(int[] m){ for(int i = 0; i< m.length-1; i++){ for(int j = i+1; j<m.length;j++){ if(m[i] > m[j]){ int d = m[i]; m[i] = m[j]; m[j] = d; } } } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 11
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
522ac5136fd43dff8e95f26e861bd437
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.Scanner; public class nxt { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int tc = sc.nextInt(); while(tc-- > 0){ int n = sc.nextInt(); int[] arr =new int[n]; for(int i =0;i < n; i++){ arr[i] = sc.nextInt(); } boolean ans = true; int[] arr2 =new int[n]; for(int i = 0; i < n;i++){ int val = sc.nextInt(); arr2[i] = val; } Arrays.sort(arr); Arrays.sort(arr2); for(int i = 0;i < n; i++){ if(arr[i] == arr2[i] || arr2[i]-arr[i] == 1) continue; else { ans = false; break; } } if(ans)System.out.println("YES"); else System.out.println("NO"); } } static class Pair{ int c,idx; // public Pair(int u, int v){ // this.c = u; // this.idx = v; // } } static class Sorting implements Comparator<Pair> { public int compare(Pair p1, Pair p2){ if(p2.c==p1.c){ return p2.c-p1.c; } return p2.c - p1.c; } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 17
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
16d481ba774046513426668698332fa3
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Scanner; import java.util.Arrays; import java.util.*; import java.lang.*; public class Prob01 { public static void main(String[] args) throws FileNotFoundException { Scanner sc = new Scanner(System.in); try{ int cases = sc.nextInt(); for(int k = 0; k < cases;k++){ int size = sc.nextInt(); Integer[] aArr = new Integer[size]; Integer[] bArr = new Integer[size]; for(int i = 0; i < size; i++){ aArr[i] = sc.nextInt(); } for(int i = 0; i < size; i++){ bArr[i] = sc.nextInt(); } Arrays.sort(aArr , Collections.reverseOrder()); Arrays.sort(bArr , Collections.reverseOrder()); boolean condition = false; for(int i = 0; i < size; i++){ if(!(bArr[i]).equals(aArr[i]) && (aArr[i] + 1) !=(bArr[i])){ System.out.println("NO"); condition = true; break; } } if(!condition){ System.out.println("YES"); } } } catch (Exception e){} } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 17
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
84756f1cabf82a8bd9634764276b5b07
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class scratch{ public static void main(String args[]){ Scanner in=new Scanner(System.in); int test=in.nextInt(); while(test-->0) { int n=in.nextInt(); int arr1[]=new int[n]; int arr2[]=new int[n]; int flg=0; for(int i=0;i<n;i++) { arr1[i]=in.nextInt(); } for(int j=0;j<n;j++) { arr2[j]=in.nextInt(); } Arrays.sort(arr1); Arrays.sort(arr2); for(int k=0;k<n;k++) { if(arr1[k]+1==arr2[k]||arr1[k]==arr2[k]) { } else { System.out.println("NO"); flg=1; break; } } if(flg!=1) System.out.println("YES"); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 17
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
791ac1f4a262fd2088cc1b601bfa8f35
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.*; import java.util.*; public class Two_Arrays{ public static void main(String[] args) throws IOException{ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); for(int i = 0; i<N; i++){ int a = sc.nextInt(); int[] amt = new int[203]; int[] amt2 = new int[203]; boolean flag = false; for(int j = 0; j<a; j++){ int t = sc.nextInt()+101; amt[t]+=1; } //+1 for(int j = 0; j<a; j++){ int t = sc.nextInt()+101; amt2[t]+=1; } for(int j = 0; j<202; j++){ //amt2 is +1 of amt amt[j] = amt[j]-amt2[j]; if(amt[j] < 0){ flag = true; break; } amt2[j+1] = amt2[j+1]-amt[j]; if(amt2[j+1] < 0){ flag = true; break; } } if(flag){ System.out.println("NO"); continue; } System.out.println("YES"); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
ed5fec3e48e572ebaf5ad9608ab6f671
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.Scanner; import java.util.List; import java.util.ArrayList; import java.util.Collections; public class MyClass { static Scanner in=new Scanner(System.in); static int n,testCases; static List<Integer> a,b; static void solve(){ Collections.sort(a); Collections.sort(b); for(int i=0;i<n;i++){ if( a.get(i)==b.get(i) ){ continue; } if( a.get(i)+1!=b.get(i) ){ System.out.println("NO"); return; } } System.out.println("YES"); } public static void main(String args[]) { testCases=in.nextInt(); for(int t=0;t<testCases;t++){ n=in.nextInt(); a=new ArrayList<>(); b=new ArrayList<>(); for(int i=0;i<n;i++){ a.add(in.nextInt() ); } for(int j=0;j<n;j++){ b.add(in.nextInt() ); } solve(); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
db86a0332f41b1012dee829c98aba109
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-- > 0) { int n=sc.nextInt(); int a[]=new int[n]; int b[]=new int[n]; for(int i=0; i<n; i++) { a[i]=sc.nextInt(); } for(int i=0; i<n; i++) { b[i]=sc.nextInt(); } Arrays.sort(a); Arrays.sort(b); boolean flag=false; for(int i=0; i<n; i++) { if(a[i] == b[i]) continue; else if(a[i]+1==b[i]) continue; else if(a[i]+1!=b[i]) { flag=true; break; } } if(flag==false) { System.out.println("YES"); } else { System.out.println("NO"); } } } catch(Exception e) { } // your code goes here } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
8633f5baa9206507dcef62528ef62b39
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class Main{ public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int a[]=new int[n]; int b[]=new int[n]; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); } for(int i=0;i<n;i++) { b[i]=sc.nextInt(); } Arrays.sort(a); Arrays.sort(b); boolean flag=true; for(int i=0;i<n;i++) { if(a[i]!=b[i] && a[i]+1!=b[i]) { System.out.println("NO"); flag=false; break; } } if(flag) { System.out.println("YES"); } } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
705972e8a4b3d55a640c7ed6affedd4c
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
// package faltu; import java.util.*; import java.util.Map.Entry; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.math.BigInteger; public class Main { // ***********************MATHS--STARTS************************************************* // private static ArrayList<Long> get_divisor(long x) { ArrayList<Long>a=new ArrayList<Long>(); for(long i=1;i*i<=x;i++) { if(x%i==0) { a.add((long) i); if(x/i!=i)a.add(x/i); } } return a; } static long[] sieve; static long[] smallestPrime; public static void sieve() { int n=4000000+1; sieve=new long[n]; smallestPrime=new long[n]; sieve[0]=1; sieve[1]=1; for(int i=2;i<n;i++){ sieve[i]=i; smallestPrime[i]=i; } for(int i=2;i*i<n;i++){ if(sieve[i]==i){ for(int j=i*i;j<n;j+=i){ if(sieve[j]==j)sieve[j]=1; if(smallestPrime[j]==j||smallestPrime[j]>i)smallestPrime[j]=i; } } } } static long nCr(long n,long r,long MOD) { if(n<r)return 0; if(r==0)return 1; return fact[(int) n]*mod_inv(fact[(int) r],MOD)%MOD*mod_inv(fact[(int) (n-r)],MOD)%MOD; } static long[]fact; static void computeFact(long n,long MOD) { fact=new long[(int)n+1]; fact[0]=1; for(int i=1;i<=n;i++)fact[i]=(fact[i-1]*i%MOD)%MOD; } static long bin_expo(long a,long b,long MOD) { if(b == 0)return 1; long ans = bin_expo(a,b/2,MOD); ans = (ans*ans)%MOD; if(b % 2!=0){ ans = (ans*a)%MOD; } return ans%MOD; } static long mod_add(long a, long b, long m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} static long mod_mul(long a, long b, long m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} static long mod_sub(long a, long b, long m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} static long mod_inv(long n,long p) {return bin_expo(n,p-2,p);} static long gcd(long a, long b){if (a == 0) {return b;}return gcd(b % a, a); } static int gcd(int a, int b){if (a == 0) {return b; }return gcd(b % a, a); } static long lcm(long a,long b){return (a / gcd(a, b)) * b;} static long min(long x,long y) {return Math.min(x, y);}static long max(long x,long y) {return Math.max(x, y);} static int min(int x,int y) {return Math.min(x, y);}static int max(int x,int y) {return Math.max(x, y);} static ArrayList<String>powof2s; static void powof2S() { long i=1; while(i<(long)2e18) { powof2s.add(String.valueOf(i)); i*=2; } } static long power(long a, long b){ a %=MOD;long out = 1; while (b > 0) { if((b&1)!=0)out = out * a % MOD; a = a * a % MOD; b >>= 1; a*=a; } return out; } static boolean coprime(int a, long l){return (gcd(a, l) == 1);} // ****************************MATHS-ENDS***************************************************** // ***********************BINARY-SEARCH STARTS*********************************************** public static int upperBound(long[] arr, long m, int l, int r) { while(l<=r) { int mid=(l+r)/2; if(arr[mid]<=m) l=mid+1; else r=mid-1; } return l; } public static int lowerBound(long[] a, long m, int l, int r) { while(l<=r) { int mid=(l+r)/2; if(a[mid]<m) l=mid+1; else r=mid-1; } return l; } public static int lowerBound(ArrayList<Integer> ar,int k){ int s=0,e=ar.size(); while (s!=e){ int mid = s+e>>1; if (ar.get(mid) <k)s=mid+1; else e=mid; } if(s==ar.size())return -1; return s; } public static int upperBound(ArrayList<Integer> ar,int k){ int s=0,e=ar.size(); while (s!=e){ int mid = s+e>>1; if (ar.get(mid) <=k)s=mid+1; else e=mid; } if(s==ar.size())return -1; return s; } public static long getClosest(long val1, long val2,long target){if (target - val1 >= val2 - target)return val2; else return val1;} static void ruffleSort(long[] a) { int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { long oi=r.nextInt(n), temp=a[i]; a[i]=a[(int)oi]; a[(int)oi]=temp; } Arrays.sort(a); } static void ruffleSort(int[] a){ int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { int oi=r.nextInt(n), temp=a[i]; a[i]=a[oi]; a[oi]=temp; } Arrays.sort(a); } int ceilIndex(int input[], int T[], int end, int s){ int start = 0; int middle; int len = end; while(start <= end){ middle = (start + end)/2; if(middle < len && input[T[middle]] < s && s <= input[T[middle+1]]){ return middle+1; }else if(input[T[middle]] < s){ start = middle+1; }else{ end = middle-1; } } return -1; } static int lowerLimitBinarySearch(ArrayList<Long> v,long k) { int n =v.size(); int first = 0,second = n; while(first <second) { int mid = first + (second-first)/2; if(v.get(mid) > k) { second = mid; }else { first = mid+1; } } if(first < n && v.get(first) < k) { first++; } return first; //1 index } public static int searchindex(long arr[], long t){int index = Arrays.binarySearch(arr, t);return (index < 0) ? -1 : index;} public static long[] sort(long[] a) {ArrayList<Long> al = new ArrayList<>();for(int i=0;i<a.length;i++) al.add(a[i]);Collections.sort(al);for(int i=0;i<a.length;i++) a[i]=al.get(i);return a;} public static int[] sort(int[] a) {ArrayList<Integer> al = new ArrayList<>();for(int i=0;i<a.length;i++) al.add(a[i]);Collections.sort(al);for(int i=0;i<a.length;i++) a[i]=al.get(i);return a;} // *******************************BINARY-SEARCH ENDS*********************************************** // *********************************GRAPHS-STARTS**************************************************** // *******----SEGMENT TREE IMPLEMENT---***** // -------------START--------------- void buildTree (int[] arr,int[] tree,int start,int end,int treeNode){ if(start==end){ tree[treeNode]=arr[start]; return; } buildTree(arr,tree,start,end,2*treeNode); buildTree(arr,tree,start,end,2*treeNode+1); tree[treeNode]=tree[treeNode*2]+tree[2*treeNode+1]; } void updateTree(int[] arr,int[] tree,int start,int end,int treeNode,int idx,int value){ if(start==end){ arr[idx]=value; tree[treeNode]=value; return; } int mid=(start+end)/2; if(idx>mid)updateTree(arr,tree,mid+1,end,2*treeNode+1,idx,value); else updateTree(arr,tree,start,mid,2*treeNode,idx,value); tree[treeNode]=tree[2*treeNode]+tree[2*treeNode+1]; } long query(int[]arr,int[]tree,int start,int end,int treeNode,int qleft,int qright) { if(start>=qleft&&end<=qright)return tree[treeNode]; if(start>qright||end<qleft)return 0; int mid=(start+end)/2; long valLeft=query(arr,tree,start,mid-1,treeNode*2,qleft,qright); long valRight=query(arr,tree,mid+1,end,treeNode*2+1,qleft,qright); return valLeft+valRight; } // -------------ENDS--------------- //***********************DSU IMPLEMENT START************************* static int parent[]; static int rank[]; static int[]Size; static void makeSet(int n){ parent=new int[n]; rank=new int[n]; Size=new int[n]; for(int i=0;i<n;i++){ parent[i]=i; rank[i]=0; Size[i]=1; } } static void union(int u,int v){ u=findpar(u); v=findpar(v); if(rank[u]<rank[v]) { parent[u]=v; Size[v]+=Size[u]; } else if(rank[v]<rank[u]) { parent[v]=u; Size[u]+=Size[v]; } else{ parent[v]=u; rank[u]++; Size[u]+=Size[v]; } } private static int findpar(int node){ if(node==parent[node])return node; return parent[node]=findpar(parent[node]); } // *********************DSU IMPLEMENT ENDS************************* // ****__________PRIMS ALGO______________________**** private static int prim(ArrayList<node>[] adj,int N,int node) { int key[] = new int[N+1]; int parent[] = new int[N+1]; boolean mstSet[] = new boolean[N+1]; for(int i = 0;i<N;i++) { key[i] = 100000000; mstSet[i] = false; } PriorityQueue<node> pq = new PriorityQueue<node>(N, new node()); key[node] = 0; parent[node] = -1; pq.add(new node( node,key[node])); for(int i = 0;i<N-1;i++) { int u = pq.poll().getV(); mstSet[u] = true; for(node it: adj[u]) { if(mstSet[it.getV()] == false && it.getW() < key[it.getV()]) { parent[it.getV()] = u; key[it.getV()] = (int) it.getW(); pq.add(new node(it.getV(), key[it.getV()])); } } } int sum=0; for(int i=1;i<N;i++) { System.out.println(key[i]); sum+=key[i]; } System.out.println(sum); return sum; } // ****____________DIJKSTRAS ALGO___________**** static int[]dist; static int dijkstra(int u,int n,ArrayList<node>adj[]) { dist=new int[n]; Arrays.fill(dist,Integer.MAX_VALUE); dist[u]=0; PriorityQueue<node>pq=new PriorityQueue<node>(new node()); pq.add(new node(u,0)); while(!pq.isEmpty()) { node v=pq.poll(); for(node it:adj[v.getV()]) { if(dist[it.getV()]>it.getW()+dist[v.getV()]) { dist[it.getV()]=(int) (it.getW()+dist[v.getV()]); pq.add(new node(it.getV(),dist[it.getV()])); } } } int sum=0; for(int i=1;i<n;i++){ System.out.println(dist[i]); sum+=dist[i]; } return sum; } private static void setGraph(int n,int m){ vis=new boolean[n+1]; indeg=new int[n+1]; // adj=new ArrayList<ArrayList<Integer>>(); // for(int i=0;i<=n;i++)adj.add(new ArrayList<>()); // for(int i=0;i<m;i++){ // int u=s.nextInt(),v=s.nextInt(); // adj.get(u).add(v); // adj.get(v).add(u); // } adj=new ArrayList[n+1]; // backadj=new ArrayList[n+1]; for(int i=0;i<=n;i++){ adj[i]=new ArrayList<Integer>(); // backadj[i]=new ArrayList<Integer>(); } for(int i=0;i<m;i++){ int u=s.nextInt(),v=s.nextInt(); adj[u].add(v); adj[v].add(u); // backadj[v].add(u); indeg[v]++; indeg[u]++; } // weighted adj // adj=new ArrayList[n+1]; // for(int i=0;i<=n;i++){ // adj[i]=new ArrayList<node>(); // } // for(int i=0;i<m;i++){ // int u=s.nextInt(),v=s.nextInt(); // long w=s.nextInt(); // adj[u].add(new node(v,w)); //// adj[v].add(new node(u,w)); // } } // *********************************GRAPHS-ENDS**************************************************** static int[][] dirs8 = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}}; static int[][] dirs4 = {{1,0},{-1,0},{0,1},{0,-1}}; //d-u-r-l static long MOD=(long) (1e9+7); static int prebitsum[][]; static boolean[] vis; static int[]indeg; // static ArrayList<ArrayList<Integer>>adj; static ArrayList<Integer> adj[]; static ArrayList<Integer> backadj[]; static FastReader s = new FastReader(System.in); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws IOException { // sieve(); // computeFact((int)1e7+1,MOD); // prebitsum=new int[2147483648][31]; // presumbit(prebitsum); // powof2S(); // // try { int tt = s.nextInt(); // int tt=1; for(int i=1;i<=tt;i++) { solver(); } out.close(); // catch(Exception e) {return;} } private static void solver() { int n=s.nextInt(); int[]a=new int[n]; int[]b=new int[n]; for(int i=0;i<n;i++)a[i]=s.nextInt(); for(int i=0;i<n;i++)b[i]=s.nextInt(); sort(a);sort(b); for(int i=0;i<n;i++) { int x=b[i]-a[i]; if(x>1||x<=-1) { out.println("NO"); return; } } out.println("YES"); } /* *********************BITS && TOOLS &&DEBUG STARTS***********************************************/ static boolean issafe(int i, int j, int r,int c,boolean[][]vis){ if (i < 0 || j < 0 || i >= r || j >= c||vis[i][j]==true)return false; else return true; } static void presumbit(int[][]prebitsum) { for(int i=1;i<=200000;i++) { int z=i; int j=0; while(z>0) { if((z&1)==1) { prebitsum[i][j]+=(prebitsum[i-1][j]+1); }else { prebitsum[i][j]=prebitsum[i-1][j]; } z=z>>1; j++; } } } static void countOfSetBit(long[]a) { for(int j=30;j>=0;j--) { int cnt=0; for(long i:a) { if((i&1<<j)==1)cnt++; } // printing the current no set bit in all array element System.out.println(cnt); } } public static String revStr(String str){String input = str;StringBuilder input1 = new StringBuilder();input1.append(input);input1.reverse();return input1.toString();} static void printA(long[] x) {for(int i=0;i<x.length;i++)System.out.print(x[i]+" ");System.out.println();} static void printA(int[] x) {for(int i=0;i<x.length;i++)System.out.print(x[i]+" ");System.out.println();} static void pc2d(boolean[][] vis) { int n=vis.length; int m=vis[0].length; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { System.out.print(vis[i][j]+" "); } System.out.println(); } } static void pi2d(char[][] a) { int n=a.length; int m=a[0].length; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { System.out.print(a[i][j]+" "); } System.out.println(); } } static void p1d(int[]a) { for(int i=0;i<a.length;i++)System.out.print(a[i]+" "); System.out.println(); } // *****************BITS && TOOLS &&DEBUG ENDS*********************************************** } // **************************I/O************************* class FastReader { public BufferedReader reader; public StringTokenizer tokenizer; public FastReader(InputStream stream) {reader = new BufferedReader(new InputStreamReader(stream), 32768);tokenizer = null;} public String next() {while (tokenizer == null || !tokenizer.hasMoreTokens()) {try {tokenizer = new StringTokenizer(reader.readLine());} catch (IOException e) {throw new RuntimeException(e);}}return tokenizer.nextToken();} public int nextInt(){ return Integer.parseInt(next());} public long nextLong() {return Long.parseLong(next());} public double nextDouble() {return Double.parseDouble(next());} public String nextLine() {String str = "";try {str = reader.readLine();}catch (IOException e) {e.printStackTrace();}return str;} } class dsu{ int n; static int parent[]; static int rank[]; static int[]Size; public dsu(int n) {this.n=n;this.parent=new int[n];this.rank=new int[n];this.Size=new int[n]; for(int i=0;i<n;i++){parent[i]=i;rank[i]=0;Size[i]=1;} } static int findpar(int node) {if(node==parent[node])return node;return parent[node]=findpar(parent[node]);} static void union(int u,int v){ u=findpar(u);v=findpar(v); if(u!=v) { if(rank[u]<rank[v]) {parent[u]=v;Size[v]+=Size[u];} else if(rank[v]<rank[u]) {parent[v]=u;Size[u]+=Size[v];} else{parent[v]=u;rank[u]++;Size[u]+=Size[v];} } } } class pair{ int x;int y; long u,v; public pair(int x,int y){this.x=x;this.y=y;} public pair(long u,long v) {this.u=u;this.v=v;} } class node implements Comparator<node>{ private int v; private long w; node(int _v, long _w) { v = _v; w = _w; } node() {} int getV() { return v; } long getW() { return w; } @Override public int compare(node node1, node node2) { if (node1.w < node2.w) return -1; if (node1.w > node2.w) return 1; return 0; } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
88a008a96834e24e668124671eb361d3
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; import java.io.*; public class A { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) throws IOException { FastReader ob =new FastReader(); try { int t=ob.nextInt(); while(t--!=0) { int n=ob.nextInt(); int[] arr1 =new int[n]; int[] arr2 =new int[n]; for(int i=0;i<n;i++) arr1[i]=ob.nextInt(); for(int i=0;i<n;i++) arr2[i]=ob.nextInt(); Arrays.sort(arr1);Arrays.sort(arr2); int low =0,high=n-1; while(low<n && arr1[low]==arr2[low]) { low++; } while(high>=0 && arr1[high]==arr2[high]) { high--; } boolean flag=true; for(int i=low;i<=high;i++) { if( (arr2[i]-arr1[i])<0 || (arr2[i]-arr1[i])>1) { flag=false; System.out.println("NO"); break; } } if(flag) System.out.println("YES"); } } catch (Exception e) { return; } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
a2660e3f6d96aec50475286f54285020
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; /** * * @author Acer */ public class TwoArrays { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); while(T-- > 0){ int n = sc.nextInt(); ArrayList<Integer> a = new ArrayList<>(); for (int i = 0; i < n; i++) { a.add(sc.nextInt()); } ArrayList<Integer> b = new ArrayList<>(); for (int i = 0; i < n; i++) { b.add(sc.nextInt()); } Collections.sort(a); Collections.sort(b); boolean flag = true; for (int i = 0; i < n; i++) { int x = a.get(i); int y = b.get(i); if(x != y && x+1 != y){ flag = false; } } if(flag){ System.out.println("YES"); } else{ System.out.println("NO"); } } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
0a7dee39ae988a3d946a9011ffdcad32
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.*; import java.util.*; public class TwoArrays { public static void main(String[] args) throws IOException { FastScanner in = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); for (int i = 1; i <= t; i++) { int n = in.nextInt(); int[] a = new int[n]; int[] b = new int[n]; List<Integer> aList = new ArrayList<Integer>(); for (int j = 0; j < n; j++) { a[j] = in.nextInt(); aList.add(a[j]); } Collections.sort(aList); List<Integer> bList = new ArrayList<Integer>(); for (int j = 0; j < n; j++) { b[j] = in.nextInt(); bList.add(b[j]); } Collections.sort(bList); boolean possible = true; for (int j = 0; j < n; j++) { int diff = bList.get(j) - aList.get(j); if ((diff > 1) || (diff < 0)) { possible = false; break; } } // 1 1 3 3 5 5 12 14 // 1 2 3 4 5 6 13 15 if (possible) { out.println("YES"); } else { out.println("NO"); } } out.close(); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { // noop } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
80e2ff13e7d4d8e0e3de47df2d6e88c0
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; public class Practice { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-- >0) { int n=sc.nextInt(); int a[]=new int[n]; int b[]=new int[n]; for(int i=0;i<n;i++) a[i]=sc.nextInt(); for(int i=0;i<n;i++) b[i]=sc.nextInt(); Arrays.sort(a); Arrays.sort(b); int k=0,i=0; for(;i<n;i++) { int res=b[i]-a[i]; if( res == 1 || res==0) { k++; }else { System.out.println("NO"); break; } } if(k>=0 && k<=n && i==n) System.out.println("YES"); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
f458960607f52eff0fc8cd2bfef4ffd3
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.*; import java.util.*; public class C { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] a = new int[n], b = new int[n]; for (int i = 0; i < n; i++) a[i] = sc.nextInt(); for (int i = 0; i < n; i++) b[i] = sc.nextInt(); shuffleSort(a); shuffleSort(b); boolean works = true; for (int i = 0; i < n; i++) works &= (a[i] == b[i] || a[i]+1 == b[i]); out.println(works? "YES" : "NO"); } out.close(); } static class Pair implements Comparable<Pair> { int first; int second; public Pair(int first, int second) { this.first = first; this.second = second; } public int compareTo(Pair p) { if (first != p.first) return Integer.compare(first, p.first); else if (second != p.second) return Integer.compare(second, p.second); else return 0; } } static final Random random = new Random(); static void shuffleSort(int[] a) { int n = a.length; for (int i = 0; i < n; i++) { int r = random.nextInt(n), temp = a[r]; a[r] = a[i]; a[i] = temp; } Arrays.sort(a); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException {return Integer.parseInt(next());} public long nextLong() throws IOException {return Long.parseLong(next());} public String nextLine() throws IOException {return br.readLine();} public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if(x.charAt(0) == '-') { neg = true; start++; } for(int i = start; i < x.length(); i++) if(x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if(dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg?-1:1); } public boolean ready() throws IOException {return br.ready();} int[] readArray(int n) throws IOException { int[] a=new int[n]; for (int i=0; i<n; i++) a[i] = nextInt(); return a; } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
c6b8de6c340221e7fd08c890173207db
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.lang.*; import java.io.InputStreamReader; import static java.lang.Math.*; import static java.lang.System.out; import java.util.*; import java.io.File; import java.io.PrintStream; import java.io.PrintWriter; import java.math.BigInteger; public class Main { /* 10^(7) = 1s. * ceilVal = (a+b-1) / b */ static final int mod = 1000000007; static final long temp = 998244353; static final long MOD = 1000000007; static final long M = (long)1e9+7; static class Pair implements Comparable<Pair> { int first, second; public Pair(int first, int second) { this.first = first; this.second = second; } public int compareTo(Pair ob) { return (int)(first - ob.first); } } static class Tuple implements Comparable<Tuple> { long first, second,third; public Tuple(long first, long second, long third) { this.first = first; this.second = second; this.third = third; } public int compareTo(Tuple o) { return (int)(o.third - this.third); } } public static class DSU { int count = 0; int[] parent; int[] rank; public DSU(int n) { count = n; parent = new int[n]; rank = new int[n]; Arrays.fill(parent, -1); Arrays.fill(rank, 1); } public int find(int i) { return parent[i] < 0 ? i : (parent[i] = find(parent[i])); } public void union(int a, int b) //Union Find by Rank { a = find(a); b = find(b); if(a == b) return; if(rank[a] < rank[b]) { parent[a] = b; } else if(rank[a] > rank[b]) { parent[b] = a; } else { parent[b] = a; rank[a] = 1 + rank[a]; } count--; } public int countConnected() { return count; } } static class Reader { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) throws IOException { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] longReadArray(int n) throws IOException { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } public static int gcd(int a, int b) { if(b == 0) return a; else return gcd(b,a%b); } public static long lcm(long a, long b) { return (a / LongGCD(a, b)) * b; } public static long LongGCD(long a, long b) { if(b == 0) return a; else return LongGCD(b,a%b); } public static long LongLCM(long a, long b) { return (a / LongGCD(a, b)) * b; } //Count the number of coprime's upto N public static long phi(long n) //euler totient/phi function { long ans = n; // for(long i = 2;i*i<=n;i++) // { // if(n%i == 0) // { // while(n%i == 0) n/=i; // ans -= (ans/i); // } // } // // if(n > 1) // { // ans -= (ans/n); // } for(long i = 2;i<=n;i++) { if(isPrime(i)) { ans -= (ans/i); } } return ans; } public static long fastPow(long x, long n) { if(n == 0) return 1; else if(n%2 == 0) return fastPow(x*x,n/2); else return x*fastPow(x*x,(n-1)/2); } public static long powMod(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) { res = (res * x) % p; } y = y >> 1; x = (x * x) % p; } return res; } static long modInverse(long n, long p) { return powMod(n, p - 2, p); } // Returns nCr % p using Fermat's little theorem. public static long nCrModP(long n, long r,long p) { if (n<r) return 0; if (r == 0) return 1; long[] fac = new long[(int)(n) + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p; return (fac[(int)(n)] * modInverse(fac[(int)(r)], p) % p * modInverse(fac[(int)(n - r)], p) % p) % p; } public static long fact(long n) { long[] fac = new long[(int)(n) + 1]; fac[0] = 1; for (long i = 1; i <= n; i++) fac[(int)(i)] = fac[(int)(i - 1)] * i; return fac[(int)(n)]; } public static long nCr(long n, long k) { long ans = 1; for(long i = 0;i<k;i++) { ans *= (n-i); ans /= (i+1); } return ans; } //Modular Operations for Addition and Multiplication. public static long perfomMod(long x) { return ((x%M + M)%M); } public static long addMod(long a, long b) { return perfomMod(perfomMod(a)+perfomMod(b)); } public static long subMod(long a, long b) { return perfomMod(perfomMod(a)-perfomMod(b)); } public static long mulMod(long a, long b) { return perfomMod(perfomMod(a)*perfomMod(b)); } public static boolean isPrime(long n) { if(n == 1) { return false; } //check only for sqrt of the number as the divisors //keep repeating so only half of them are required. So,sqrt. for(int i = 2;i*i<=n;i++) { if(n%i == 0) { return false; } } return true; } public static List<Long> SieveList(int n) { boolean prime[] = new boolean[(int)(n+1)]; Arrays.fill(prime, true); List<Long> l = new ArrayList<>(); for (long p = 2; p*p<=n; p++) { if (prime[(int)(p)] == true) { for(long i = p*p; i<=n; i += p) { prime[(int)(i)] = false; } } } for (long p = 2; p<=n; p++) { if (prime[(int)(p)] == true) { l.add(p); } } return l; } public static int countDivisors(int x) { int c = 0; for(int i = 1;i*i<=x;i++) { if(x%i == 0) { if(x/i != i) { c+=2; } else { c++; } } } return c; } public static long log2(long n) { long ans = (long)(log(n)/log(2)); return ans; } public static boolean isPow2(long n) { return (n != 0 && ((n & (n-1))) == 0); } public static boolean isSq(int x) { long s = (long)Math.round(Math.sqrt(x)); return s*s==x; } /* * * >= <= 0 1 2 3 4 5 6 7 5 5 5 6 6 6 7 7 lower_bound for 6 at index 3 (>=) upper_bound for 6 at index 6(To get six reduce by one) (<=) */ public static int LowerBound(int a[], int x) { int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r; } public static int UpperBound(int a[], int x) { int l=-1, r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } public static void Sort(int[] a) { List<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); // Collections.reverse(l); //Use to Sort decreasingly for (int i=0; i<a.length; i++) a[i]=l.get(i); } public static void ssort(char[] a) { List<Character> l = new ArrayList<>(); for (char i : a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } public static void main(String[] args) throws Exception { Reader sc = new Reader(); PrintWriter fout = new PrintWriter(System.out); int tt = sc.nextInt(); while(tt-- > 0) { int n = sc.nextInt(); int[] a = sc.readArray(n), b = sc.readArray(n); Sort(a); Sort(b); boolean ok = true; for(int i = 0;i<n;i++) { if(a[i] == b[i]) continue; if(a[i] + 1 == b[i]) continue; ok = false; break; } fout.println((ok == true) ? "YES" : "NO"); } fout.close(); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
9681b9f29e7e984f7fa33777afd9f7ee
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.lang.*; import java.io.InputStreamReader; import static java.lang.Math.*; import static java.lang.System.out; import java.util.*; import java.io.File; import java.io.PrintStream; import java.io.PrintWriter; import java.math.BigInteger; public class Main { /* 10^(7) = 1s. * ceilVal = (a+b-1) / b */ static final int mod = 1000000007; static final long temp = 998244353; static final long MOD = 1000000007; static final long M = (long)1e9+7; static class Pair implements Comparable<Pair> { int first, second; public Pair(int first, int second) { this.first = first; this.second = second; } public int compareTo(Pair ob) { return (int)(first - ob.first); } } static class Tuple implements Comparable<Tuple> { long first, second,third; public Tuple(long first, long second, long third) { this.first = first; this.second = second; this.third = third; } public int compareTo(Tuple o) { return (int)(o.third - this.third); } } public static class DSU { int count = 0; int[] parent; int[] rank; public DSU(int n) { count = n; parent = new int[n]; rank = new int[n]; Arrays.fill(parent, -1); Arrays.fill(rank, 1); } public int find(int i) { return parent[i] < 0 ? i : (parent[i] = find(parent[i])); } public void union(int a, int b) //Union Find by Rank { a = find(a); b = find(b); if(a == b) return; if(rank[a] < rank[b]) { parent[a] = b; } else if(rank[a] > rank[b]) { parent[b] = a; } else { parent[b] = a; rank[a] = 1 + rank[a]; } count--; } public int countConnected() { return count; } } static class Reader { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) throws IOException { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] longReadArray(int n) throws IOException { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } public static int gcd(int a, int b) { if(b == 0) return a; else return gcd(b,a%b); } public static long lcm(long a, long b) { return (a / LongGCD(a, b)) * b; } public static long LongGCD(long a, long b) { if(b == 0) return a; else return LongGCD(b,a%b); } public static long LongLCM(long a, long b) { return (a / LongGCD(a, b)) * b; } //Count the number of coprime's upto N public static long phi(long n) //euler totient/phi function { long ans = n; // for(long i = 2;i*i<=n;i++) // { // if(n%i == 0) // { // while(n%i == 0) n/=i; // ans -= (ans/i); // } // } // // if(n > 1) // { // ans -= (ans/n); // } for(long i = 2;i<=n;i++) { if(isPrime(i)) { ans -= (ans/i); } } return ans; } public static long fastPow(long x, long n) { if(n == 0) return 1; else if(n%2 == 0) return fastPow(x*x,n/2); else return x*fastPow(x*x,(n-1)/2); } public static long powMod(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) { res = (res * x) % p; } y = y >> 1; x = (x * x) % p; } return res; } static long modInverse(long n, long p) { return powMod(n, p - 2, p); } // Returns nCr % p using Fermat's little theorem. public static long nCrModP(long n, long r,long p) { if (n<r) return 0; if (r == 0) return 1; long[] fac = new long[(int)(n) + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p; return (fac[(int)(n)] * modInverse(fac[(int)(r)], p) % p * modInverse(fac[(int)(n - r)], p) % p) % p; } public static long fact(long n) { long[] fac = new long[(int)(n) + 1]; fac[0] = 1; for (long i = 1; i <= n; i++) fac[(int)(i)] = fac[(int)(i - 1)] * i; return fac[(int)(n)]; } public static long nCr(long n, long k) { long ans = 1; for(long i = 0;i<k;i++) { ans *= (n-i); ans /= (i+1); } return ans; } //Modular Operations for Addition and Multiplication. public static long perfomMod(long x) { return ((x%M + M)%M); } public static long addMod(long a, long b) { return perfomMod(perfomMod(a)+perfomMod(b)); } public static long subMod(long a, long b) { return perfomMod(perfomMod(a)-perfomMod(b)); } public static long mulMod(long a, long b) { return perfomMod(perfomMod(a)*perfomMod(b)); } public static boolean isPrime(long n) { if(n == 1) { return false; } //check only for sqrt of the number as the divisors //keep repeating so only half of them are required. So,sqrt. for(int i = 2;i*i<=n;i++) { if(n%i == 0) { return false; } } return true; } public static List<Long> SieveList(int n) { boolean prime[] = new boolean[(int)(n+1)]; Arrays.fill(prime, true); List<Long> l = new ArrayList<>(); for (long p = 2; p*p<=n; p++) { if (prime[(int)(p)] == true) { for(long i = p*p; i<=n; i += p) { prime[(int)(i)] = false; } } } for (long p = 2; p<=n; p++) { if (prime[(int)(p)] == true) { l.add(p); } } return l; } public static int countDivisors(int x) { int c = 0; for(int i = 1;i*i<=x;i++) { if(x%i == 0) { if(x/i != i) { c+=2; } else { c++; } } } return c; } public static long log2(long n) { long ans = (long)(log(n)/log(2)); return ans; } public static boolean isPow2(long n) { return (n != 0 && ((n & (n-1))) == 0); } public static boolean isSq(int x) { long s = (long)Math.round(Math.sqrt(x)); return s*s==x; } /* * * >= <= 0 1 2 3 4 5 6 7 5 5 5 6 6 6 7 7 lower_bound for 6 at index 3 (>=) upper_bound for 6 at index 6(To get six reduce by one) (<=) */ public static int LowerBound(int a[], int x) { int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r; } public static int UpperBound(int a[], int x) { int l=-1, r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } public static void Sort(long[] a) { List<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); // Collections.reverse(l); //Use to Sort decreasingly for (int i=0; i<a.length; i++) a[i]=l.get(i); } public static void ssort(char[] a) { List<Character> l = new ArrayList<>(); for (char i : a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } public static void main(String[] args) throws Exception { Reader sc = new Reader(); PrintWriter fout = new PrintWriter(System.out); int tt = sc.nextInt(); while(tt-- > 0) { int n = sc.nextInt(); int[] a = sc.readArray(n), b = sc.readArray(n); Arrays.sort(a); Arrays.sort(b); List<Integer> list = new ArrayList<>(), l2 = new ArrayList<>(); for(int i = 0;i<n;i++) { if(a[i] != b[i]) { list.add((a[i]+1)); l2.add(b[i]); } } boolean ok = true; Collections.sort(list); for(int i = 0;i<list.size();i++) { if(list.get(i) != l2.get(i)) { ok = false; break; } } fout.println((ok == true) ? "YES" : "NO"); } fout.close(); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
b1a868b341801780ed05a33340ed31ff
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.*; import java.util.*; public class TwoArrays{ static long mod = 1000000007L; static MyScanner sc = new MyScanner(); static void solve() { int n = sc.nextInt(); int arr[] = sc.readIntArray(n); int brr[] = sc.readIntArray(n); sort(arr); sort(brr); for(int i = 0;i<n;i++){ if(arr[i]!=brr[i] && arr[i]+1 !=brr[i]){ out.println("NO"); return; } } out.println("Yes"); } static long gcd(long a,long b){ if(b==0) return a; return gcd(b,a%b); } static String reverse(String str){ char arr[] = str.toCharArray(); int i = 0; int j = arr.length-1; while(i<j){ char temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; i++; j--; } String st = new String(arr); return st; } static boolean isprime(int n){ if(n==1 || n==2) return false; if(n==3) return true; if(n%2==0 || n%3==0) return false; for(int i = 5;i*i<=n;i+= 6){ if(n%i== 0 || n%(i+2)==0){ return false; } } return true; } static class Pair implements Comparable<Pair>{ int val; int freq; Pair(int v,int f){ val = v; freq = f; } public int compareTo(Pair p){ return this.freq - p.freq; } } public static void main(String[] args) { out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while(t-- >0){ // solve(); solve(); } // Stop writing your solution here. ------------------------------------- out.close(); } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int[] readIntArray(int n){ int arr[] = new int[n]; for(int i = 0;i<n;i++){ arr[i] = Integer.parseInt(next()); } return arr; } int[] reverse(int arr[]){ int n= arr.length; int i = 0; int j = n-1; while(i<j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; j--;i++; } return arr; } long[] readLongArray(int n){ long arr[] = new long[n]; for(int i = 0;i<n;i++){ arr[i] = Long.parseLong(next()); } return arr; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } private static void sort(int[] arr) { List<Integer> list = new ArrayList<>(); for (int i=0; i<arr.length; i++){ list.add(arr[i]); } Collections.sort(list); // collections.sort uses nlogn in backend for (int i = 0; i < arr.length; i++){ arr[i] = list.get(i); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
7578a663a33027a0bbf242058f42e35a
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class TwoArrays { public static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int tc = scanner.nextInt(); while (tc-->0){ int size = scanner.nextInt(); int [] array = new int[size]; int [] array1 = new int[size]; for (int i =0;i< array.length;i++){ array[i] = scanner.nextInt(); } for (int i =0;i< array.length;i++){ array1[i] = scanner.nextInt(); } Arrays.sort(array); Arrays.sort(array1); String ans = "YES"; for (int i =0;i< array.length;i++){ if (array[i]==array1[i]){ ans = "Yes"; }else if (array[i] + 1 !=array1[i]){ ans = "NO"; break; }else ans = "Yes"; } System.out.println(ans); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
1ecb9ce8cdf4ac280e4732b3e6e91983
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class fastTemp { public static void main(String[] args) throws IOException, NumberFormatException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int b[]=new int[n]; int arr[] = new int[n]; for(int i=0;i<n;i++){ arr[i] = sc.nextInt(); } for(int i=0;i<n;i++){ b[i] = sc.nextInt(); } Arrays.sort(arr); Arrays.sort(b); int count=0; boolean f = false; for(int i=0;i<n;i++){ if(arr[i]-b[i]>0 || Math.abs(arr[i]-b[i])>1 ){ System.out.println("NO"); f = true; break; } } if(!f){ System.out.println("YES"); } } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
95b7f65320a81ee8a1669f6577f4e8f0
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.StringTokenizer; /* * Author : Imtiaz Adar */ public class x1584C { public static void main(String[] args) { FastScanner scan = new FastScanner(); int T = scan.nextInt(); while(T-- > 0) { int size = scan.nextInt(); int[] a = scan.readIntArray(size); int[] b = scan.readIntArray(size); sort(a); sort(b); boolean possible = true; for(int i = 0; i < size; i++) { if((b[i] - a[i]) == 1 || (b[i] - a[i]) == 0) continue; else possible = false; } if(!possible) System.out.println("NO"); else System.out.println("YES"); } } static void sort(int[] arr) { ArrayList<Integer> list = new ArrayList<Integer>(); for(int item : arr) list.add(item); Collections.sort(list); for(int i = 0; i < arr.length; i++) arr[i] = list.get(i); } static class FastScanner{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next(){ while(!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch(IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readIntArray(int size) { int[] x = new int[size]; for(int i = 0; i < x.length; i++) { x[i] = nextInt(); } return x; } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
fa19e4fb459c0896ff54aa6e87dc989d
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.*; import java.util.*; public class TwoArrays { public static void main(String[] args) { new TwoArrays().run(); } BufferedReader br; PrintWriter out; long mod = (long) (1e9 + 7), inf = (long) (3e18); class pair { int F, S; pair(int f, int s) { F = f; S = s; } } void solve() { int t = ni(); while(t-- > 0) { //TODO: int n = ni(); int[] a= na(n); int[] b= na(n); Arrays.sort(a); Arrays.sort(b); boolean pos=true; for(int i=0; i<n; i++){ if(a[i]==b[i] || a[i]+1==b[i]){ continue; } pos=false; break; } if(pos){ out.println("YES"); } else{ out.println("NO"); } } } // -------- I/O Template ------------- char nc() { return ns().charAt(0); } String nLine() { try { return br.readLine(); } catch(IOException e) { return "-1"; } } double nd() { return Double.parseDouble(ns()); } long nl() { return Long.parseLong(ns()); } int ni() { return Integer.parseInt(ns()); } int[] na(int n) { int a[] = new int[n]; for(int i = 0; i < n; i++) a[i] = ni(); return a; } StringTokenizer ip; String ns() { if(ip == null || !ip.hasMoreTokens()) { try { ip = new StringTokenizer(br.readLine()); if(ip == null || !ip.hasMoreTokens()) ip = new StringTokenizer(br.readLine()); } catch(IOException e) { throw new InputMismatchException(); } } return ip.nextToken(); } void run() { try { if (System.getProperty("ONLINE_JUDGE") == null) { br = new BufferedReader(new FileReader("/media/ankanchanda/Data/WORKPLACE/DS and CP/Competitive Programming/VSCODE/IO/input.txt")); out = new PrintWriter("/media/ankanchanda/Data/WORKPLACE/DS and CP/Competitive Programming/VSCODE/IO/output.txt"); } else { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } } catch (FileNotFoundException e) { System.out.println(e); } solve(); out.flush(); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
c233ce149e990ded1022a04c5bb91344
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; import java.io.*; public class C { public static void main(String[] args) throws IOException { FastReader in = new FastReader(System.in); PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out)); int t = in.nextInt(); for (int tt = 0; tt < t; tt++) { int n = in.nextInt(); int[] a = in.readArray(n); int[] b = in.readArray(n); Sort(a); Sort(b); boolean yes = true; for (int i = 0; i < n; i++) { if (a[i] != b[i] && ++a[i] != b[i]) { yes = false; break; } } pw.println(yes ? "YES" : "NO"); } pw.close(); } static int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } static boolean isPalindrom(String txt) { return txt.equals(new StringBuilder(txt).reverse().toString()); } public static boolean isSorted(int[] arr) { for (int i = 1; i < arr.length; i++) if (arr[i] < arr[i - 1]) return false; return true; } static long binaryExponentiation(long x, long n) { if (n == 0) return 1; else if (n % 2 == 0) return binaryExponentiation(x * x, n / 2); else return x * binaryExponentiation(x * x, (n - 1) / 2); } public static void Sort(int[] a) { ArrayList<Integer> lst = new ArrayList<>(); for (int i : a) lst.add(i); Collections.sort(lst); for (int i = 0; i < lst.size(); i++) a[i] = lst.get(i); } static void debug(Object... obj) { System.err.println(Arrays.deepToString(obj)); } static class Pair implements Comparable<Pair> { int first, second; public Pair(int first, int second) { this.first = first; this.second = second; } public int compareTo(Pair ob) { return first - ob.first; } } static class FastReader { InputStream is; private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; public FastReader(InputStream is) { this.is = is; } public int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } public boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } public String next() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public String nextLine() { int c = skip(); StringBuilder sb = new StringBuilder(); while (!isEndOfLine(c)) { sb.appendCodePoint(c); c = readByte(); } return sb.toString(); } public int nextInt() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = (num << 3) + (num << 1) + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public long nextLong() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = (num << 3) + (num << 1) + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public double nextDouble() { return Double.parseDouble(next()); } public char[] next(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } public char readChar() { return (char) skip(); } public long[] readArrayL(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = nextLong(); return arr; } public int[] readArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = nextInt(); return arr; } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
33f7ede638717fdc242e67f8560dd2f1
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.*; import java.util.*; public class Main2 { static long mod = 998244353; public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int test = in.nextInt(); for(int t = 1; t<=test;t++) { int n = in.nextInt(); int a[] = new int[n]; int b[] = new int[n]; Arrays.setAll(a,i->in.nextInt()); Arrays.setAll(b,i->in. nextInt()); Arrays.sort(a); Arrays.sort(b); boolean flag = true; for(int i = 0;i<n;i++){ if(a[i]==b[i]){ continue; } else if(a[i]+1==b[i]){ continue; } else { flag = false; break; } } if(flag){ pw.println("YES"); } else { pw.println("NO"); } } pw.close(); } static void debug(Object... obj) { System.err.println(Arrays.deepToString(obj)); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
6b4b278ee9f28aad0ae0814beed00841
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.Arrays; import java.util.Scanner; import java.util.stream.IntStream; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int tc = 0; tc < t; ++tc) { int n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < a.length; ++i) { a[i] = sc.nextInt(); } int[] b = new int[n]; for (int i = 0; i < b.length; ++i) { b[i] = sc.nextInt(); } System.out.println(solve(a, b) ? "YES" : "NO"); } sc.close(); } static boolean solve(int[] a, int[] b) { Arrays.sort(a); Arrays.sort(b); return IntStream.range(0, a.length).allMatch(i -> a[i] == b[i] || a[i] + 1 == b[i]); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
202856f1c879ae056b7f1c5d0b6c5749
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.util.StringTokenizer; public class Two_Arrays { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) { return -ret; } return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) { buffer[0] = -1; } } private byte read() throws IOException { if (bufferPointer == bytesRead) { fillBuffer(); } return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) { return; } din.close(); } } public static void main(String Args[]) throws java.lang.Exception { try { Reader obj = new Reader(); int t = obj.nextInt(); while (t > 0) { t--; int n = obj.nextInt(); int a[] = new int[n]; int b[] = new int[n]; int i; boolean bool = true; for (i=0;i<n;i++) { a[i] = obj.nextInt(); } for (i=0;i<n;i++) { b[i] = obj.nextInt(); } Arrays.sort(a); Arrays.sort(b); for (i=0;i<n;i++) { if (a[i] == b[i] || (a[i] + 1) == b[i]) { continue; } else { bool = false; break; } } if (bool) { System.out.println ("YES"); } else { System.out.println ("NO"); } } }catch(Exception e){ return; } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
127924c76e4eede4f6344e227934d0c0
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.*; import java.util.*; public class A { public static long gcd(long a, long b) { return a == 0 ? b : gcd(b, a % b); } public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter o = new PrintWriter(System.out); int t1 = sc.nextInt(); while (t1-- > 0) { int n = sc.nextInt(); Integer l[] = new Integer[n]; Integer a[] = new Integer[n]; for (int i = 0; i < n; i++) l[i] = sc.nextInt(); for (int i = 0; i < n; i++) a[i] = sc.nextInt(); Arrays.sort(a); Arrays.sort(l); for (int i = 0; i < n; i++) { if (a[i] - l[i] > 1 || a[i] - l[i] < 0) { System.out.println("NO"); break; } if (i == n - 1) System.out.println("YES"); } } o.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } int[] readArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
184a46fccfdc3e0a9cfc3eca6ed37eca
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; import java.io.*; public class Main{ static Scanner sc = new Scanner(new BufferedInputStream(System.in)); static int sc(){return sc.nextInt();} static double scd(){return sc.nextDouble();} static char[] carr(){return sc.next().toCharArray();} static long scl(){return sc.nextLong();} static String scs(){return sc.next();} static char scf(){return sc.next().charAt(0);} static char[] chars(){String s = sc.next();char[] c = new char[s.length()+1];for(int i = 1;i<=s.length();i++){c[i] = s.charAt(i-1);}return c;} // static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // static int toi(String s){return Integer.parseInt(s);} // static double tod(String s) {return Double.parseDouble(s);} // static long tol(String s) {return Long.parseLong(s);} // static int[] geti() throws Exception{String[] s = sarr();int[] a = new int[s.length];for(int i = 0;i<s.length;i++) {a[i] = Integer.parseInt(s[i]);}return a;} // static long[] getl() throws Exception{String[] s = sarr();long[] a = new long[s.length];for(int i = 0;i<s.length;i++) {a[i] = Long.parseLong(s[i]);}return a;} // static double[] getd() throws Exception{String[] s = sarr();double[] a = new double[s.length];for(int i = 0;i<s.length;i++) {a[i] = Double.parseDouble(s[i]);}return a;} // static char[] carr() throws Exception{return br.readLine().toCharArray();} // static char[] chars() throws Exception{char[] c = carr();char[] res = new char[c.length+1];System.arraycopy(c, 0, res, 1, c.length);return res;} // static String[] sarr() throws Exception{return br.readLine().split(" ");} // static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); // static int sc() throws Exception{in.nextToken();return (int)in.nval;} // static double scd() throws Exception{in.nextToken();return in.nval;} static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); static void print(Object o){out.print(o);} static void println(Object o){out.println(o);} static void println(){out.println();} static void Y(){println("YES");} static void N(){println("NO");} static final int N = (int)2e6+10,M = 2010,P = 131,MOD = (int)1e9+7; static int n; static int[] dx = new int[]{0,-1,0,1},dy = new int[]{-1,0,1,0}; static int INF= 0x3f3f3f3f; // static int[] h = new int[N],e = new int[N],ne = new int[N],w = new int[N]; // static int idx; static int[] a = new int[N]; static int[] b = new int[N]; public static void main(String[] args) throws Exception{ int t = sc(); while(t-->0){ n = sc(); for(int i = 0;i<n;i++) a[i] = sc(); for(int i = 0;i<n;i++) b[i] = sc(); Arrays.sort(a,0,n); Arrays.sort(b,0,n); boolean f = true; for(int i = 0;i<n;i++){ if(b[i] - a[i] == 0||b[i] - a[i] == 1) continue; else f = false; break; } println(f?"YES":"NO"); } out.close(); } static class D{int x,y;D(int x,int y){this.x = x;this.y = y;}} }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
554a708273eb0790b64797f2a1a8d8fb
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int tc = sc.nextInt(); while(tc-->0) { int n = sc.nextInt(); int a[] = new int[n]; int b[] = new int[n]; boolean flag =true; for(int i=0;i<n;i++)a[i]=sc.nextInt(); for(int i=0;i<n;i++)b[i]=sc.nextInt(); Arrays.sort(a); Arrays.sort(b); if(Arrays.equals(a,b)) flag=true; else { for(int i=0;i<n;i++){ if(a[i]!=b[i]){ if(a[i]+1!=b[i]) { flag=false; break; } } } } if(flag) System.out.println("YES"); else System.out.println("NO"); } sc.close(); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
27ca15e71f2f163f3b5c248a18ac28d0
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int tc = sc.nextInt(); while(tc-->0) { int n = sc.nextInt(); int a[] = new int[n]; int b[] = new int[n]; boolean flag =true; for(int i=0;i<n;i++)a[i]=sc.nextInt(); for(int i=0;i<n;i++)b[i]=sc.nextInt(); Arrays.sort(a); Arrays.sort(b); if(Arrays.equals(a,b)) flag=true; else { for(int i=0;i<n;i++){ if(a[i]!=b[i]){ if(a[i]+1!=b[i]) { flag=false; break; } } } } if(flag) System.out.println("YES"); else System.out.println("NO"); } sc.close(); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
eb7579f14f63c4b82c65a586b7249fab
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class C1584 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); for (int t=0; t<T; t++) { int N = in.nextInt(); int[] A = new int[N]; int[] B = new int[N]; for (int n=0; n<N; n++) { A[n] = in.nextInt(); } for (int n=0; n<N; n++) { B[n] = in.nextInt(); } Arrays.sort(A); Arrays.sort(B); boolean possible = true; for (int n=0; n<N; n++) { if (A[n] != B[n] && A[n]+1 != B[n]) { possible = false; break; } } System.out.println(possible ? "YES" : "NO"); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
aa235340120f185edc3c4e9b9d0902fe
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int t = scn.nextInt(); while(t-->0){ int n = scn.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for(int i = 0; i<n; i++){ a[i] = scn.nextInt(); } for(int i = 0; i<n; i++){ b[i] = scn.nextInt(); } Arrays.sort(a); Arrays.sort(b); boolean flag = true; for(int i = 0; i<n; i++){ if(a[i] != b[i]){ if(a[i] + 1 != b[i]){ flag = false; break; } } } if(flag) System.out.println("yes"); else System.out.println("no"); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
6691f83666d7ca34429b6dea8b0cb377
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.lang.Math; import java.lang.String; import java.util.Arrays; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.Scanner; import java.util.Collections; import java.util.StringTokenizer; public class testfile { public static void main(String args[]) throws java.io.IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t = Integer.parseInt(br.readLine()); while(t-->0) { int n = Integer.parseInt(br.readLine()); String s[] = br.readLine().split(" "); String s1[] = br.readLine().split(" "); int a[] = new int[n]; int b[] = new int[n], detect = 1; for(int i = 0; i<n; i++) a[i] = Integer.parseInt(s[i]); for(int i = 0; i<n; i++) b[i] = Integer.parseInt(s1[i]); Arrays.sort(a);Arrays.sort(b); for(int i = 0; i<n; i++) if(b[i]!=a[i] && a[i]+1!=b[i]) {detect = 0;break;}; if(detect == 0) out.println("no"); else out.println("yes"); } out.close(); } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
cc4e7ddc5bed41282705ac309a314c5c
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; public class practice2 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int[] arr=new int[n]; int[] brr=new int[n]; for (int i = 0; i < n; i++) { arr[i]=sc.nextInt(); } for (int i = 0; i < n; i++) { brr[i]=sc.nextInt(); } Arrays.sort(arr); Arrays.sort(brr); int count=0; for (int i = 0; i < n; i++) { if(arr[i]==brr[i] || (arr[i]+1)==brr[i]){ count++; } } if(count==n){ System.out.println("YES"); } else{ System.out.println("NO"); } } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
7012a59ffcf0d9a1f6ce0ecc9467cf81
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.Scanner; import java.util.List; import java.util.ArrayList; import java.util.Collections; public class MyClass { static Scanner in=new Scanner(System.in); static int n,testCases; static List<Integer> a,b; static void solve(){ Collections.sort(a); Collections.sort(b); for(int i=0;i<n;i++){ if( a.get(i)==b.get(i) ){ continue; } if( a.get(i)+1!=b.get(i) ){ System.out.println("NO"); return; } } System.out.println("YES"); } public static void main(String args[]) { testCases=in.nextInt(); for(int t=0;t<testCases;t++){ n=in.nextInt(); a=new ArrayList<>(); b=new ArrayList<>(); for(int i=0;i<n;i++){ a.add(in.nextInt() ); } for(int j=0;j<n;j++){ b.add(in.nextInt() ); } solve(); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
fb71924f1ff719ae094d53f8ec83ef78
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.sql.Time; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.Deque; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.PriorityQueue; import java.util.Queue; import java.util.Scanner; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; public class Practice1 { static int[] sort(int[] arr) { int n=arr.length; ArrayList<Integer> al=new ArrayList<>(); for(int i=0;i<n;i++) { al.add(arr[i]); } Collections.sort(al); for(int i=0;i<n;i++) { arr[i]=al.get(i); } return arr; } public static void main (String[] args) { PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); // out.print(); //out.println(); FastReader sc=new FastReader(); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int[] arr=new int[n]; int[] brr=new int[n]; for(int i=0;i<n;i++) { arr[i]=sc.nextInt(); } for(int i=0;i<n;i++) { brr[i]=sc.nextInt(); } sort(arr); sort(brr); String ans="YES"; for(int i=0;i<n;i++) { if(!(brr[i]-arr[i]==1||brr[i]==arr[i])) { ans="NO"; } } out.println(ans); } out.close(); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
784cfd16a6cf8eb47de882269c813b72
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; import java.io.*; public class codeforces1584C { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int numCases = Integer.parseInt(br.readLine()); for (int rep = 0; rep<numCases;rep++) { int length = Integer.parseInt(br.readLine()); int [] a = new int[length]; int [] b = new int[length]; StringTokenizer st = new StringTokenizer(br.readLine()); for (int i=0;i<length;i++) { a[i]=Integer.parseInt(st.nextToken()); } st = new StringTokenizer(br.readLine()); for (int i=0;i<length;i++) { b[i]=Integer.parseInt(st.nextToken()); } Arrays.sort(a); Arrays.sort(b); boolean bo = true; for (int i=0;i<length;i++) { if (a[i]-b[i]>=1 || a[i]-b[i]<=-2) { bo = false; } } if (bo) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
fefd10fa795f5520520dfa760c4bc9cb
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.*; import java.io.*; public class CFsolve { public static void main(String[] args) { FastScanner input = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = input.nextInt(); while(t-- > 0){ byte n = input.nextByte(); StringBuilder str1 = new StringBuilder(); int[]arr = new int[n]; int[]arr2 = new int[n]; StringBuilder str2 = new StringBuilder(); String isPossible = "YES"; for(byte i = 0; i<n; i++){ arr[i] = input.nextByte(); str1.append(arr[i]); } for(byte i = 0; i<n; i++){ arr2[i] = input.nextByte(); str2.append(arr2[i]); } if(str1.toString().equals(str2.toString())){ out.println("YES"); out.close(); continue; } sort(arr); sort(arr2); int i = 0; for(int element : arr){ if(element != arr2[i] && element+1 != arr2[i]) { isPossible = "NO"; break; } i++; } out.println(isPossible); } out.close(); } static int LCM(int a, int b){ return a/gcd(a,b) * b; } static long LCM(long a, long b){ return (a/gcd(a,b) * b); } static int gcd(int a,int b){ while(b>0){ a%=b; a=a^b; b=a^b; a=a^b; } return a; } static long gcd(long a,long b){ while(b>0){ a%=b; a=a^b; b=a^b; a=a^b; } return a; } static void swap(int a, int b){ a = a^b; b = a^b; a = a^b; } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } byte nextByte(){return Byte.parseByte(next());} long nextLong() { return Long.parseLong(next()); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
af6f5e972a07e7bd01d3010fb776c561
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class C { public static void main(String[] args) { FastScanner fs=new FastScanner(); int t=fs.nextInt(); while (t-->0) { int n=fs.nextInt(); int []a=new int [n]; int [] b=new int [n]; for (int i=0;i<n;i++) a[i]=fs.nextInt(); for (int i=0;i<n;i++) b[i]=fs.nextInt(); Arrays.sort(a); Arrays.sort(b); int f=1; for (int i=0;i<n;i++) if (a[i]==b[i] || a[i]+1==b[i]) continue; else { f=0; System.out.println("NO"); break; } if (f==1) System.out.println("YES"); } } static class FastScanner{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); public String next() { while (!st.hasMoreElements()) try { st=new StringTokenizer(br.readLine()); }catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt () { return Integer.parseInt(next()); } long nextLong () { return Long.parseLong(next()); } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
e181ecc839c665d268bf57d1d8d42e79
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.io.*; import java.util.*; public class cf { public static void main(String[] args){ FastScanner sc = new FastScanner(); int z = sc.nextInt(); //int z=1; while(z-- > 0){ int n=sc.nextInt(); int a[]=new int[n]; int b[]=new int[n]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } for(int i=0;i<n;i++){ b[i]=sc.nextInt(); } Arrays.sort(a); Arrays.sort(b); boolean check=true; for(int i=0;i<n;i++){ int dif=b[i]-a[i]; if(dif>1 || dif<0){ System.out.println("NO"); check =false; break; } } if(check){ System.out.println("YES"); } } } } ///////////////////////////////////////////////////////////// //BINARY SEARCH /*Arrays.binarySearch(arr,key); if key--> present return index else return -(index where it would be inserted)-1*/ ////////////////////////////////////////////////////////////// /* VALUE JUST GREATER THAN X find_min(int[]arr,int x){ int l=-1; int r=arr.length; while(r>l+1){ int mid=(l+r)/2; if(arr[mid]<x){ l=mid; } else{ r=mid; } } return r; } VALUE JUST SMALLER THAN X find_max(int[]arr,int x){ int l=-1; int r=arr.length; while(r>l+1){ int mid=(l+r)/2; if(arr[mid]<=x){ l=mid; } else{ r=mid; } } return l; } */ ////////////////////////////////////////////////////////////// // LCM AND GCD /* public static int gcd(int a,int b){ if(b == 0){ return a; } return gcd(b,a%b); } public static int lcm(int a,int b){ return (a / gcd(a, b)) * b; }*/ /////////////////////////////////////////////////////////////////////////////////// //Iterator /*Iterator iterator = object.iterator(); while (iterator.hasNext()) { System.out.print(iterator.next() + " "); }*/ /////////////////////////////////////////////////////////////////////////////////// class FastScanner { //I don't understand how this works lmao private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } public char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] nextInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
9805f5369e3b4a3fbbec3d7e8d7245bf
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.util.Scanner; import java.util.*; public class Main { public static void main(String[] args) { // write your code here Scanner sc = new Scanner(System.in); int test = sc.nextInt(); while (test-- != 0) { int n = sc.nextInt(); int [] a = new int[n]; int [] b = new int[n]; for(int i=0;i<n;i++){ a[i] = sc.nextInt(); } for(int i=0;i<n;i++){ b[i] = sc.nextInt(); } Arrays.sort(a); Arrays.sort(b); for(int i=0;i<n;i++){ if(a[i] != b[i]){ a[i]+= 1; } } boolean istrue = true; Arrays.sort(a); for(int i=0;i<n;i++){ if(a[i] != b[i]){ istrue = false; break; } } if(istrue){ System.out.println("yes"); } else { System.out.println("no"); } } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output
PASSED
3d4928f53e816dfc01f8d720329d5955
train_109.jsonl
1636869900
You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$: Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$. Choose $$$k$$$ distinct array indices $$$1 \le i_1 &lt; i_2 &lt; \ldots &lt; i_k \le n$$$. Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged. Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?
256 megabytes
import java.lang.reflect.Array; import java.util.*; import java.io.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static class Matches implements Comparable<Matches>{ public int quantity; public int amount; public Matches(Integer nameArg, Integer IPArg){ quantity = nameArg; amount = IPArg; } @Override public String toString(){ return quantity+" "+amount; } @Override public int compareTo(Matches o) { if(amount==o.amount) return 0; else if(amount<o.amount) return 1; else return -1; } } public static void main(String[] args) { // write your code here PrintWriter out = new PrintWriter(System.out); FastReader scan = new FastReader(); Task solver = new Task(); solver.solve(1,scan,out); out.close(); } static class Task{ public void solve(int testNumber, FastReader scan, PrintWriter out) { int [][] L = {{1,3,3,4,5,5,6},{2,2,4,1,1,4,2}}; /*Pattern pattern = Pattern.compile("[B]+"); //REGEX template Matcher matcher = pattern.matcher(s);*/ int t=1; t = scan.nextInt(); for(int i=0; i<t;i++){ int n = scan.nextInt(); //long n = scan.nextLong(); ArrayList<Integer> list = new ArrayList<>(); ArrayList<Integer> list2 = new ArrayList<>(); for(int j=0;j<n;j++){ list.add(scan.nextInt()); } for(int j=0;j<n;j++){ list2.add(scan.nextInt()); } Collections.sort(list,Collections.reverseOrder()); Collections.sort(list2,Collections.reverseOrder()); boolean isOK=true; for(int j=0;j<n;j++){ int d = list2.get(j)-list.get(j); if(d!=0 && d!=1){ isOK=false; break; } } if(isOK){ out.println("YES"); }else{ out.println("NO"); } } } public boolean isParenthesys(String s){ boolean isOK=true; int number =0; for(int j=0;j<s.length();j++){ if(s.charAt(j)=='('){ number++; }else{ number--; } if(number<0){ isOK=false; } } return isOK && number==0; } public static String parenthesys(int n){ String answer = ""; for(int j = 0; j<n;j++){ answer+="("; } for(int j = 0; j<n;j++){ answer+=")"; } return answer; } public static long digitsSum(long n){ long sum=0; while(n!=0){ sum+=n%10; n=n/10; } return sum; } public static boolean isFibonachi(int n){ int f1=1; int f2=1; while(f2<=n){ if(f2==n){ return true; } int temp = f1+f2; f1=f2; f2=temp; } return false; } public static boolean isValid(int x, int y, int n){ if(x<0 || y<0 || x>=n || y>=n){ return false; } return true; } public static long factorial(long n){ if(n<=1){ return 1; }else{ return n*factorial(n-1); } } public static long DBD(long a, long b){ if (b==0) return a; return DBD(b,a%b); } public static boolean isPrime(int n){ if(n<2){ return false; } if(n==2){ return true; } for(int i=2; i<Math.sqrt(n)+1 ;i++){ if(n%i==0){ return false; } } return true; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(new File(s))); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["3\n3\n-1 1 0\n0 0 2\n1\n0\n2\n5\n1 2 3 4 5\n1 2 3 4 5"]
1 second
["YES\nNO\nYES"]
NoteIn the first test case, we can make the following transformation: Choose $$$k = 2$$$. Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$. Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$. Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.
Java 8
standard input
[ "greedy", "math", "sortings" ]
6ca98e655007bfb86f1039c9f096557e
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).
900
For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).
standard output