-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcf1382A.java
More file actions
37 lines (34 loc) · 1 KB
/
cf1382A.java
File metadata and controls
37 lines (34 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.util.Scanner;
public class cf1382A {
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 m = sc.nextInt();
int b[] = new int[m];
int pos[] = new int[1001]; //to track
boolean found = false;
int s = 0; //first num in subsequence
for(int i=0; i<n; i++) {
a[i] = sc.nextInt();
pos[a[i]]++;
}
for(int i=0; i<m; i++) {
b[i] = sc.nextInt();
if(pos[b[i]] > 0) {
found = true;
s = b[i];
}
}
if(found) {
System.out.println("YES");
System.out.println(1 + " " + s);
}
else
System.out.println("NO");
}
sc.close();
}
}