SEARCH1 - Other search problem
Tác giả: happyboy99x
Ngôn ngữ: C++
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX = 1e5 + 5;
int a[MAX], b[MAX], c[MAX], countA[MAX], countC[MAX], m, n, p;
bool markB[MAX];
void enter() {
scanf("%d%d%d", &m, &n, &p);
for(int i = 0; i < m; ++i) scanf("%d", a+i), ++countA[a[i]];
for(int i = 0; i < n; ++i) scanf("%d", b+i), markB[b[i]] = true;
for(int i = 0; i < p; ++i) scanf("%d", c+i);
}
int check(int u, int v) { /*Check [u, v)*/
if(v - u < m) return 0;
for(int i = u; i < v; ++i) ++countC[c[i]];
for(int i = 0; i < m; ++i) if(countA[a[i]] > countC[a[i]]) return 0;
for(int i = u; i < v; ++i) countC[c[i]] = 0;
return v - u;
}
void solve() {
int res = 0; c[p] = b[0];
for(int s = 0, i = 0; i <= p; ++i) if(markB[c[i]]) res = max(res, check(s, i)), s = i+1;
printf("%d\n", res);
}
int main() {
enter();
solve();
return 0;
}