#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d))
#define szof(x) ((int)(x).size())
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#define mkp make_pair
const int INF = 2147483647;
const int LNF = INF*INF;
const int MOD = 1000000007;
const int mod = 998244353;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
const int MAX = 200010;
int n, k, r;
int arr[MAX];
int cnt[MAX];
int req[MAX];
int sat;
int lptr, rptr;
int res;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>k>>r;
FOR(i, 1, n, 1){
cin>>arr[i];
}
FOR(i, 1, r, 1){
int type;
cin>>type;
cin>>req[type];
}
res = INF;
lptr = 1, rptr = 0;
sat = 0;
int type;
while(lptr <= n){
while(sat < r){
rptr++;
if(rptr > n) break;
type = arr[rptr];
cnt[type]++;
if(cnt[type] == req[type]){
sat++;
}
}
if(rptr > n) break;
res = min(res, rptr - lptr + 1);
//cerr<<"["<<lptr<<", "<<rptr<<"]"<<endl;
type = arr[lptr];
if(cnt[type] == req[type]){
sat--;
}
cnt[type]--;
lptr++;
}
if(res == INF){
cout<<"impossible"<<'\n';
}
else{
cout<<res<<'\n';
}
return 0;
}
# |
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 |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
320 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 |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
2252 KB |
Output is correct |
2 |
Correct |
29 ms |
2244 KB |
Output is correct |
3 |
Correct |
37 ms |
2244 KB |
Output is correct |
4 |
Correct |
31 ms |
2304 KB |
Output is correct |
5 |
Correct |
23 ms |
3600 KB |
Output is correct |
6 |
Correct |
20 ms |
2196 KB |
Output is correct |
7 |
Correct |
25 ms |
2348 KB |
Output is correct |
8 |
Correct |
27 ms |
4628 KB |
Output is correct |
9 |
Correct |
29 ms |
2884 KB |
Output is correct |
10 |
Correct |
17 ms |
2176 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 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 |
332 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 |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
288 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
4888 KB |
Output is correct |
2 |
Correct |
38 ms |
4420 KB |
Output is correct |
3 |
Correct |
38 ms |
4132 KB |
Output is correct |
4 |
Correct |
21 ms |
2188 KB |
Output is correct |
5 |
Correct |
54 ms |
5600 KB |
Output is correct |
6 |
Correct |
65 ms |
6760 KB |
Output is correct |
7 |
Correct |
26 ms |
2928 KB |
Output is correct |
8 |
Correct |
26 ms |
3372 KB |
Output is correct |
9 |
Correct |
19 ms |
2184 KB |
Output is correct |
10 |
Correct |
21 ms |
2244 KB |
Output is correct |
11 |
Correct |
18 ms |
2280 KB |
Output is correct |
12 |
Correct |
19 ms |
2360 KB |
Output is correct |
13 |
Correct |
28 ms |
3580 KB |
Output is correct |
14 |
Correct |
18 ms |
2208 KB |
Output is correct |
15 |
Correct |
19 ms |
2476 KB |
Output is correct |
16 |
Correct |
27 ms |
4652 KB |
Output is correct |
17 |
Correct |
24 ms |
2904 KB |
Output is correct |
18 |
Correct |
20 ms |
2292 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 |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
316 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |