SEARCH1 - Other search problem
Tác giả: ladpro98
Ngôn ngữ: C++
#include <bits/stdc++.h>
const int N = 100005;
using namespace std;
int m, n, p;
int a[N], b[N], c[N], Fa[N], Fb[N], cnt[N];
int main() {
scanf("%d %d %d", &m, &n, &p);
for(int i = 1; i <= m; i++) scanf("%d", a + i), cnt[a[i]] = ++Fa[a[i]];
for(int i = 1; i <= n; i++) scanf("%d", b + i), Fb[b[i]]++;
for(int i = 1; i <= p; i++) scanf("%d", c + i);
int j = 0, res = 0;
for(int i = 1; i <= p; i = j = j + 1)
if (Fb[c[i]] == 0) {
int k = 0;
for(; j <= p && Fb[c[j]] == 0; j++)
if (cnt[c[j]] > 0) k++, cnt[c[j]]--;
if (k == m) res = max(res, j - i);
for(int t = i; t < j; t++) cnt[c[t]] = Fa[c[t]];
}
printf("%d", res);
return 0;
}