#include <bits/stdc++.h>
using namespace std;
const int maxn5 = 3e5 + 10;
int a[maxn5], req[maxn5];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n, k, r;
cin >> n >> k >> r;
for(int i = 0; i < n; i++)
cin >> a[i];
for(int i = 0; i < r; i++){
int a, b; cin >> a >> b;
req[a] = b;
}
int id = 0;
req[a[0]]--;
int rem = r, ans = n + 10;
if(req[a[0]] == 0)
rem--;
for(int i = 0; i < n; i++){
while(rem && id < n - 1){
id++;
req[a[id]]--;
if(req[a[id]] == 0)
rem--;
}
if(rem == 0)
ans = min(ans, id - i + 1);
req[a[i]]++;
if(req[a[i]] == 1)
rem++;
if(id == i){
id++;
req[a[id]]--;
if(req[a[id]] == 0)
rem--;
}
}
if(ans > n)
cout << "impossible" << endl;
else
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
376 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1476 KB |
Output is correct |
2 |
Correct |
12 ms |
1412 KB |
Output is correct |
3 |
Correct |
14 ms |
1476 KB |
Output is correct |
4 |
Correct |
13 ms |
1500 KB |
Output is correct |
5 |
Correct |
27 ms |
2492 KB |
Output is correct |
6 |
Correct |
12 ms |
1484 KB |
Output is correct |
7 |
Correct |
12 ms |
1568 KB |
Output is correct |
8 |
Correct |
19 ms |
3012 KB |
Output is correct |
9 |
Correct |
15 ms |
1952 KB |
Output is correct |
10 |
Correct |
12 ms |
1484 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
316 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
3140 KB |
Output is correct |
2 |
Correct |
23 ms |
2856 KB |
Output is correct |
3 |
Correct |
19 ms |
2552 KB |
Output is correct |
4 |
Correct |
12 ms |
1484 KB |
Output is correct |
5 |
Correct |
35 ms |
3564 KB |
Output is correct |
6 |
Correct |
33 ms |
3824 KB |
Output is correct |
7 |
Correct |
16 ms |
2116 KB |
Output is correct |
8 |
Correct |
20 ms |
2336 KB |
Output is correct |
9 |
Correct |
12 ms |
1416 KB |
Output is correct |
10 |
Correct |
13 ms |
1412 KB |
Output is correct |
11 |
Correct |
13 ms |
1476 KB |
Output is correct |
12 |
Correct |
13 ms |
1484 KB |
Output is correct |
13 |
Correct |
18 ms |
2620 KB |
Output is correct |
14 |
Correct |
13 ms |
1476 KB |
Output is correct |
15 |
Correct |
17 ms |
1612 KB |
Output is correct |
16 |
Correct |
26 ms |
3016 KB |
Output is correct |
17 |
Correct |
15 ms |
1988 KB |
Output is correct |
18 |
Correct |
12 ms |
1436 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
328 KB |
Output is correct |
23 |
Correct |
1 ms |
352 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
324 KB |
Output is correct |
31 |
Correct |
1 ms |
324 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |