原题链接:https://www.acwing.com/activity/content/problem/content/2981/

思路:基础的双指针算法。

#include <iostream>

#define N 100005

int a[N], b[N];

int n, m;

int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
for (int i = 0; i < m; ++i) scanf("%d", &b[i]);
int i = 0, j = 0;
while (j < m && i < n) {
if (a[i] == b[j]) i++;
j++;
}
printf("%s", (i == n ? "Yes" : "No"));
return 0;
}