#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;int K;int m;
int ar[1000006];
int freq[1000006];
int isin[1000006];
int nd[1000006];
int ans;
int tot;
void ad(int v){
freq[v]++;
if(isin[v]&&nd[v]==freq[v]){
tot++;
}
}
void del(int v){
if(isin[v]&&nd[v]==freq[v]){
tot--;
}
freq[v]--;
}
signed main() {
cin>>n>>K>>m;
for(int i=1;i<=n;i++){
cin>>ar[i];
}
for(int i=1;i<=m;i++){
int pl;int v;
cin>>pl>>v;
isin[pl]=1;
nd[pl]=v;
}
ans=n+1;
tot=0;
int rit=0;
for(int i=1;i<=n;i++){
while(tot<m&&rit<=n-1){ad(ar[++rit]);}
if(tot==m){
ans=min(ans,rit-i+1);
}
// cout<<i<<" "<<rit<<" "<<tot<<endl;
del(ar[i]);
}
if(ans==n+1){
cout<<"impossible\n";return 0;
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
356 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
2176 KB |
Output is correct |
2 |
Correct |
23 ms |
2248 KB |
Output is correct |
3 |
Correct |
24 ms |
2252 KB |
Output is correct |
4 |
Correct |
31 ms |
2252 KB |
Output is correct |
5 |
Correct |
51 ms |
3732 KB |
Output is correct |
6 |
Correct |
22 ms |
2240 KB |
Output is correct |
7 |
Correct |
27 ms |
2384 KB |
Output is correct |
8 |
Correct |
52 ms |
4788 KB |
Output is correct |
9 |
Correct |
38 ms |
2892 KB |
Output is correct |
10 |
Correct |
25 ms |
2296 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
264 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
5424 KB |
Output is correct |
2 |
Correct |
59 ms |
4812 KB |
Output is correct |
3 |
Correct |
50 ms |
4472 KB |
Output is correct |
4 |
Correct |
23 ms |
2252 KB |
Output is correct |
5 |
Correct |
74 ms |
6376 KB |
Output is correct |
6 |
Correct |
77 ms |
8136 KB |
Output is correct |
7 |
Correct |
40 ms |
3020 KB |
Output is correct |
8 |
Correct |
47 ms |
3532 KB |
Output is correct |
9 |
Correct |
23 ms |
2260 KB |
Output is correct |
10 |
Correct |
24 ms |
2280 KB |
Output is correct |
11 |
Correct |
28 ms |
2260 KB |
Output is correct |
12 |
Correct |
23 ms |
2260 KB |
Output is correct |
13 |
Correct |
40 ms |
3696 KB |
Output is correct |
14 |
Correct |
23 ms |
2208 KB |
Output is correct |
15 |
Correct |
28 ms |
2384 KB |
Output is correct |
16 |
Correct |
44 ms |
4792 KB |
Output is correct |
17 |
Correct |
36 ms |
2892 KB |
Output is correct |
18 |
Correct |
23 ms |
2260 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
388 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |