2 solutions

  • 0
    @ 2025-8-29 15:01:57
    #include<bits/stdc++.h>
    using namespace std;
    int a[100010],b[100010];
    int main(){
    	int n,m;
    	cin>>n>>m; 
    	for(int i=1;i<=n;i++)cin>>a[i];
    	for(int i=1;i<=m;i++)cin>>b[i];
    	for(int i=1,j=1;j<=m;j++){
    		if(a[i]==b[j])i++;
    		if(i==n+1){
    			cout<<"Yes"<<endl;
    			return 0;
    		}
    	}
    	cout<<"No";
    	return 0;
    }
    
    
    • -1
      @ 2026-7-30 20:52:21
      #include<bits/stdc++.h>
      using namespace std;
      int a[100000],b[100000];
      int main()
      {
      	int n,m;
      	cin>>n>>m;
      	for(int i=1;i<=n;i++)cin>>a[i];
      	for(int i=1;i<=m;i++)cin>>b[i];
      	for(int i=1,j=1;j<=m;j++)
      	{
      		if(a[i]==b[j])i++;
      		if(i==n+1)
      		{
      			cout<<"Yes"<<endl;
      			return 0;
      		}
      	}
      	cout<<"No";
      	return 0;
      }
      • 1

      Information

      ID
      2882
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      3
      Tags
      # Submissions
      37
      Accepted
      12
      Uploaded By