-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Common_Subsequence.cpp
More file actions
54 lines (52 loc) · 1.02 KB
/
Copy pathA_Common_Subsequence.cpp
File metadata and controls
54 lines (52 loc) · 1.02 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<queue>
#define ll long long int
#define pb push_back
#define fo(i,n) for(int i=0;i<n;i++)
#define ff(i,n) for(int i=n-1;i>=0;i--)
#define fff(i,a,b) for(int i = a; i < b ; i++)
#define pb push_back
#define YES cout<< 'YES' << endl
#define NO cout<< 'NO' << endl
using namespace std;
const int E = 2e3 + 100;
const int mod = 1e9 + 7;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;cin>>t;
while(t--)
{
ll n,m;cin>>n>>m;
ll a[n],b[m];
fff(i,0,n) cin>>a[i];
fff(i,0,m) cin>>b[i];
sort(a,a+n);
sort(b,b+m);
ll ans = 0;
ll i=0,j=0;
while(i<n and j<m)
{
if(a[i]==b[j])
{
ans = a[i];
break;
}
else if(a[i]<b[j])
{
i++;
}
else j++;
}
if(ans==0) cout<< "NO" <<'\n';
else
{
cout<< "YES" <<'\n';
cout<< 1 << " " << ans <<'\n';
}
}
return 0;
} //Code Contributed by Harshit Varshney