1 条题解

  • 0
    @ 2026-8-7 21:04:59
    #include<iostream>
    #include<algorithm>
    using namespace std;
    
    int main(){
        int t;
        cin>>t;
        while(t--){
            int n,m,a[1010],b[1010];
            cin>>n>>m;
            for(int i=1;i<=n;i++){
                cin>>a[i];
            }
            sort(a+1,a+1+n);
            bool z=0;
            for(int i=1;i<=m;i++){
                cin>>b[i];
                int x=lower_bound(a+1,a+1+n,b[i])-a;
                if(a[x]==b[i]&&!z){
                    z=1;
                    cout<<"YES\n1 "<<b[i]<<"\n";
                }
            }
            if(!z){
                cout<<"NO\n";
            }
        }
    }
    
    • 1

    信息

    ID
    7287
    时间
    1000ms
    内存
    256MiB
    难度
    1
    标签
    递交数
    18
    已通过
    4
    上传者