判断子序列

发布于 2022-07-28  6 次阅读


#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 998244353;
int n, m, a[N], b[N];

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