#include <bits/stdc++.h>
using namespace std;
constexpr int M = 200005;
int tab[M];
int wymagane[M];
bool czyPotrzeba[M];
int main(){
cin.tie(0)->sync_with_stdio(0);
int n, k, ileL;
cin>>n>>k>>ileL;
for(int i=1; i<=n; i++) cin>>tab[i];
for(int i=1; i<=ileL; i++){
int a, b;
cin>>a>>b;
wymagane[a] = b;
czyPotrzeba[a] = 1;
}
int l = 1;
int ileJuz = 0;
int wynik = M + 2;
int dlugosc = 0;
for(int r=1; r<=n; r++){
while(l<=n && ileJuz < ileL){
wymagane[ tab[l] ]--;
if(wymagane[tab[l]] == 0 && czyPotrzeba[tab[l]]==1) ileJuz++;
dlugosc++;
if(ileJuz == ileL) wynik = min(wynik, dlugosc);
l++;
}
wymagane[ tab[r] ]++;
if(wymagane[tab[r]]==1 && czyPotrzeba[tab[r]]==1) ileJuz--;
dlugosc--;
if(ileJuz == ileL) wynik = min(wynik, dlugosc);
}
if(wynik==M+2) cout<<"impossible"<<endl;
else cout<<wynik<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1508 KB |
Output is correct |
2 |
Correct |
10 ms |
1624 KB |
Output is correct |
3 |
Correct |
10 ms |
1628 KB |
Output is correct |
4 |
Correct |
11 ms |
1628 KB |
Output is correct |
5 |
Correct |
17 ms |
2648 KB |
Output is correct |
6 |
Correct |
9 ms |
1628 KB |
Output is correct |
7 |
Correct |
10 ms |
1748 KB |
Output is correct |
8 |
Correct |
15 ms |
3164 KB |
Output is correct |
9 |
Correct |
12 ms |
2236 KB |
Output is correct |
10 |
Correct |
10 ms |
1776 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
3164 KB |
Output is correct |
2 |
Correct |
20 ms |
3156 KB |
Output is correct |
3 |
Correct |
16 ms |
2648 KB |
Output is correct |
4 |
Correct |
10 ms |
1576 KB |
Output is correct |
5 |
Correct |
22 ms |
3676 KB |
Output is correct |
6 |
Correct |
26 ms |
4160 KB |
Output is correct |
7 |
Correct |
14 ms |
2140 KB |
Output is correct |
8 |
Correct |
15 ms |
2524 KB |
Output is correct |
9 |
Correct |
9 ms |
1628 KB |
Output is correct |
10 |
Correct |
10 ms |
1548 KB |
Output is correct |
11 |
Correct |
13 ms |
1764 KB |
Output is correct |
12 |
Correct |
9 ms |
1492 KB |
Output is correct |
13 |
Correct |
12 ms |
2652 KB |
Output is correct |
14 |
Correct |
9 ms |
1628 KB |
Output is correct |
15 |
Correct |
10 ms |
1628 KB |
Output is correct |
16 |
Correct |
15 ms |
3116 KB |
Output is correct |
17 |
Correct |
11 ms |
2140 KB |
Output is correct |
18 |
Correct |
9 ms |
1628 KB |
Output is correct |
19 |
Correct |
1 ms |
480 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
468 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
464 KB |
Output is correct |
33 |
Correct |
0 ms |
376 KB |
Output is correct |