#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n, k, r; cin >> n >> k >> r;
vector<int> v(n);
for(auto &x : v)cin >> x;
vector<int> ha(k,0), wa(k,0);
for(int i = 0; i < r; ++i){
int a, b; cin >> a >> b;
wa[a] = b;
}
int l = -1, ri = -1, go = 0, best = 1<<30;
while(++ri < n){
ha[v[ri]]++;
if(ha[v[ri]] == wa[v[ri]])go++;
if(go == r){
while(go == r){
++l;
ha[v[l]]--;
if(ha[v[l]] == wa[v[l]]-1)go--;
}
best = min(best,ri-l+1);
}
}
cout << (best == (1<<30) ? "impossible" : to_string(best)) << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1152 KB |
Output is correct |
2 |
Correct |
15 ms |
1280 KB |
Output is correct |
3 |
Correct |
16 ms |
1152 KB |
Output is correct |
4 |
Correct |
15 ms |
1152 KB |
Output is correct |
5 |
Correct |
22 ms |
1784 KB |
Output is correct |
6 |
Correct |
13 ms |
1152 KB |
Output is correct |
7 |
Correct |
15 ms |
1152 KB |
Output is correct |
8 |
Correct |
22 ms |
2688 KB |
Output is correct |
9 |
Correct |
22 ms |
1152 KB |
Output is correct |
10 |
Correct |
14 ms |
1152 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
0 ms |
384 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
1792 KB |
Output is correct |
2 |
Correct |
31 ms |
1784 KB |
Output is correct |
3 |
Correct |
26 ms |
1664 KB |
Output is correct |
4 |
Correct |
15 ms |
1152 KB |
Output is correct |
5 |
Correct |
35 ms |
1920 KB |
Output is correct |
6 |
Correct |
38 ms |
2556 KB |
Output is correct |
7 |
Correct |
19 ms |
1152 KB |
Output is correct |
8 |
Correct |
22 ms |
1280 KB |
Output is correct |
9 |
Correct |
14 ms |
1152 KB |
Output is correct |
10 |
Correct |
15 ms |
1152 KB |
Output is correct |
11 |
Correct |
16 ms |
1152 KB |
Output is correct |
12 |
Correct |
15 ms |
1152 KB |
Output is correct |
13 |
Correct |
20 ms |
1792 KB |
Output is correct |
14 |
Correct |
14 ms |
1152 KB |
Output is correct |
15 |
Correct |
16 ms |
1152 KB |
Output is correct |
16 |
Correct |
23 ms |
2688 KB |
Output is correct |
17 |
Correct |
18 ms |
1152 KB |
Output is correct |
18 |
Correct |
14 ms |
1152 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
0 ms |
384 KB |
Output is correct |
28 |
Correct |
0 ms |
384 KB |
Output is correct |
29 |
Correct |
0 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |