#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m, k, A[200005], req[200005], cur[200005];
void solve(){
cin >> n >> m >> k;
for(int i = 1; i <= n; i++)cin >> A[i];
int cnt = 0;
for(int i = 1; i <= k; i++){
int a, b; cin >> a >> b;
req[a] = max(req[a], b);
}
int ans = 1e18, l = 1;
for(int i = 0; i < m; i++)if(!req[i])cnt++;
for(int i = 1; i <= n; i++){
cur[A[i]]++;
if(cur[A[i]] == req[A[i]])cnt++;
while(cnt == m){
ans = min(ans, i - l + 1);
cur[A[l]]--;
if(cur[A[l]] == req[A[l]] - 1)cnt--;
l++;
}
}
if(ans == 1e18)cout << "impossible";
else cout << ans;
cout << '\n';
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int tc = 1;
//cin >> tc;
for(int tc1=1;tc1<=tc;tc1++){
// cout << "Case #" << tc1 << ": ";
solve();
}
}
Compilation message
dna.cpp:41:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
41 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 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 |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 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 |
528 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
2400 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
352 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
2272 KB |
Output is correct |
2 |
Correct |
10 ms |
2396 KB |
Output is correct |
3 |
Correct |
15 ms |
2444 KB |
Output is correct |
4 |
Correct |
12 ms |
3176 KB |
Output is correct |
5 |
Correct |
14 ms |
4712 KB |
Output is correct |
6 |
Correct |
11 ms |
3220 KB |
Output is correct |
7 |
Correct |
14 ms |
2428 KB |
Output is correct |
8 |
Correct |
19 ms |
5752 KB |
Output is correct |
9 |
Correct |
12 ms |
3844 KB |
Output is correct |
10 |
Correct |
10 ms |
3164 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
480 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
5836 KB |
Output is correct |
2 |
Correct |
20 ms |
5212 KB |
Output is correct |
3 |
Correct |
17 ms |
4188 KB |
Output is correct |
4 |
Correct |
14 ms |
2392 KB |
Output is correct |
5 |
Correct |
25 ms |
6480 KB |
Output is correct |
6 |
Correct |
37 ms |
6996 KB |
Output is correct |
7 |
Correct |
13 ms |
3160 KB |
Output is correct |
8 |
Correct |
23 ms |
3412 KB |
Output is correct |
9 |
Correct |
13 ms |
2392 KB |
Output is correct |
10 |
Correct |
15 ms |
2396 KB |
Output is correct |
11 |
Correct |
10 ms |
2392 KB |
Output is correct |
12 |
Correct |
9 ms |
2392 KB |
Output is correct |
13 |
Correct |
14 ms |
3928 KB |
Output is correct |
14 |
Correct |
9 ms |
2392 KB |
Output is correct |
15 |
Correct |
14 ms |
2396 KB |
Output is correct |
16 |
Correct |
22 ms |
4700 KB |
Output is correct |
17 |
Correct |
12 ms |
2904 KB |
Output is correct |
18 |
Correct |
10 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
2520 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
520 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2392 KB |
Output is correct |
26 |
Correct |
1 ms |
2392 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2648 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |