// header file
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// pragma
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
// macros
#define endl "\n"
#define ll long long
#define mp make_pair
#define ins insert
#define lb lower_bound
#define pb push_back
#define ub upper_bound
#define lll __int128
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
int main() {
ios_base::sync_with_stdio(0); cin.tie(NULL);
int n, k, r;
cin >> n >> k >> r;
int a[n];
for(int i = 0; i < n; ++i)
cin >> a[i];
int cnt[k];
memset(cnt, 0, sizeof(cnt));
for(int i = 0; i < r; ++i) {
int b, q;
cin >> b >> q;
cnt[b] = q;
}
int right = 0, nonzero = r;
int ans = 1e9;
for(int i = 0; i < n; ++i) {
while(right < n && nonzero) {
--cnt[a[right]];
if(cnt[a[right]] == 0)
--nonzero;
++right;
}
if(nonzero)
break;
ans = min(ans, right - i);
if(cnt[a[i]] == 0) {
++nonzero;
}
++cnt[a[i]];
}
if(ans == 1e9)
cout << "impossible" << endl;
else
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1468 KB |
Output is correct |
2 |
Correct |
15 ms |
1484 KB |
Output is correct |
3 |
Correct |
14 ms |
1484 KB |
Output is correct |
4 |
Correct |
14 ms |
1492 KB |
Output is correct |
5 |
Correct |
18 ms |
2468 KB |
Output is correct |
6 |
Correct |
12 ms |
1364 KB |
Output is correct |
7 |
Correct |
12 ms |
1596 KB |
Output is correct |
8 |
Correct |
19 ms |
3104 KB |
Output is correct |
9 |
Correct |
16 ms |
1980 KB |
Output is correct |
10 |
Correct |
12 ms |
1484 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
216 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
3124 KB |
Output is correct |
2 |
Correct |
26 ms |
2864 KB |
Output is correct |
3 |
Correct |
19 ms |
2508 KB |
Output is correct |
4 |
Correct |
12 ms |
1468 KB |
Output is correct |
5 |
Correct |
29 ms |
3624 KB |
Output is correct |
6 |
Correct |
33 ms |
3768 KB |
Output is correct |
7 |
Correct |
18 ms |
2132 KB |
Output is correct |
8 |
Correct |
19 ms |
2256 KB |
Output is correct |
9 |
Correct |
14 ms |
1492 KB |
Output is correct |
10 |
Correct |
13 ms |
1364 KB |
Output is correct |
11 |
Correct |
16 ms |
1456 KB |
Output is correct |
12 |
Correct |
13 ms |
1464 KB |
Output is correct |
13 |
Correct |
18 ms |
2484 KB |
Output is correct |
14 |
Correct |
12 ms |
1492 KB |
Output is correct |
15 |
Correct |
13 ms |
1580 KB |
Output is correct |
16 |
Correct |
19 ms |
2996 KB |
Output is correct |
17 |
Correct |
15 ms |
2004 KB |
Output is correct |
18 |
Correct |
12 ms |
1484 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
320 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
312 KB |
Output is correct |
27 |
Correct |
0 ms |
320 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
320 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
316 KB |
Output is correct |