#include <bits/stdc++.h>
using namespace std;
#define rep(n) for (int i = 0; i < n; ++i)
#define rep2(n) for (int j = 0; j < n; ++j)
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k, r;
cin >> n >> k >> r;
int d[n], cnt[k] = {}, mst[k] = {}, b, q, cur = 0, start = 0, ans = INT_MAX;
rep (n) cin >> d[i];
rep (r) {
cin >> b >> q;
mst[b] = q;
}
rep (n) {
cnt[d[i]]++;
if (cnt[d[i]]==mst[d[i]]) cur++;
while (cur==r) {
ans = min(ans, i-start+1);
if (cnt[d[start]]==mst[d[start]]) cur--;
cnt[d[start++]]--;
}
}
if (ans!=INT_MAX) cout << ans << "\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 |
0 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 |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 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 |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1536 KB |
Output is correct |
2 |
Correct |
16 ms |
1536 KB |
Output is correct |
3 |
Correct |
16 ms |
1536 KB |
Output is correct |
4 |
Correct |
16 ms |
1536 KB |
Output is correct |
5 |
Correct |
22 ms |
2840 KB |
Output is correct |
6 |
Correct |
15 ms |
1536 KB |
Output is correct |
7 |
Correct |
15 ms |
1664 KB |
Output is correct |
8 |
Correct |
23 ms |
3968 KB |
Output is correct |
9 |
Correct |
18 ms |
2176 KB |
Output is correct |
10 |
Correct |
15 ms |
1536 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 |
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 |
0 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3448 KB |
Output is correct |
2 |
Correct |
29 ms |
3192 KB |
Output is correct |
3 |
Correct |
25 ms |
2944 KB |
Output is correct |
4 |
Correct |
15 ms |
1536 KB |
Output is correct |
5 |
Correct |
36 ms |
4088 KB |
Output is correct |
6 |
Correct |
41 ms |
4624 KB |
Output is correct |
7 |
Correct |
20 ms |
2176 KB |
Output is correct |
8 |
Correct |
24 ms |
2560 KB |
Output is correct |
9 |
Correct |
15 ms |
1536 KB |
Output is correct |
10 |
Correct |
17 ms |
1536 KB |
Output is correct |
11 |
Correct |
17 ms |
1536 KB |
Output is correct |
12 |
Correct |
16 ms |
1536 KB |
Output is correct |
13 |
Correct |
21 ms |
2936 KB |
Output is correct |
14 |
Correct |
14 ms |
1568 KB |
Output is correct |
15 |
Correct |
16 ms |
1792 KB |
Output is correct |
16 |
Correct |
23 ms |
3968 KB |
Output is correct |
17 |
Correct |
19 ms |
2304 KB |
Output is correct |
18 |
Correct |
16 ms |
1536 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 |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 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 |
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 |