#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
int n, k, r;
int a[200001], req[200001], cnt[200001];
bool check(int len) {
int num_fulfilled = 0;
fill(cnt, cnt + n, 0);
FOR(i, 0, len) {
cnt[a[i]]++;
if (cnt[a[i]] == req[a[i]]) num_fulfilled++;
}
if (num_fulfilled == r) return true;
FOR(i, len, n) {
if (cnt[a[i - len]] == req[a[i - len]]) num_fulfilled--;
cnt[a[i - len]]--;
cnt[a[i]]++;
if (cnt[a[i]] == req[a[i]]) num_fulfilled++;
if (num_fulfilled == r) return true;
}
return false;
}
int main() {
iostream::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k >> r;
FOR(i, 0, n) cin >> a[i];
FOR(i, 0, r) {
int x;
cin >> x >> req[x];
}
int l = 1, r = n;
while (l != r) {
int mid = (l + r) / 2;
if (check(mid)) r = mid;
else l = mid + 1;
}
if (check(n)) cout << l << '\n';
else cout << "impossible\n";
return 0;
}
# |
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 |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 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 |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 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 |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
2304 KB |
Output is correct |
2 |
Correct |
31 ms |
2296 KB |
Output is correct |
3 |
Correct |
22 ms |
2432 KB |
Output is correct |
4 |
Correct |
29 ms |
2304 KB |
Output is correct |
5 |
Correct |
38 ms |
3072 KB |
Output is correct |
6 |
Correct |
26 ms |
2432 KB |
Output is correct |
7 |
Correct |
27 ms |
2432 KB |
Output is correct |
8 |
Correct |
44 ms |
3200 KB |
Output is correct |
9 |
Correct |
35 ms |
2944 KB |
Output is correct |
10 |
Correct |
33 ms |
2304 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 |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 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 |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
512 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
3960 KB |
Output is correct |
2 |
Correct |
50 ms |
3704 KB |
Output is correct |
3 |
Correct |
54 ms |
3456 KB |
Output is correct |
4 |
Correct |
16 ms |
2304 KB |
Output is correct |
5 |
Correct |
50 ms |
4472 KB |
Output is correct |
6 |
Correct |
68 ms |
4728 KB |
Output is correct |
7 |
Correct |
36 ms |
2944 KB |
Output is correct |
8 |
Correct |
45 ms |
3200 KB |
Output is correct |
9 |
Correct |
32 ms |
2432 KB |
Output is correct |
10 |
Correct |
32 ms |
2304 KB |
Output is correct |
11 |
Correct |
22 ms |
2304 KB |
Output is correct |
12 |
Correct |
29 ms |
2304 KB |
Output is correct |
13 |
Correct |
36 ms |
3072 KB |
Output is correct |
14 |
Correct |
26 ms |
2336 KB |
Output is correct |
15 |
Correct |
28 ms |
2432 KB |
Output is correct |
16 |
Correct |
45 ms |
3200 KB |
Output is correct |
17 |
Correct |
35 ms |
2944 KB |
Output is correct |
18 |
Correct |
32 ms |
2304 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
512 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 |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |