#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define MAXN 200010
using namespace std;
int n, k, r, a[MAXN];
set<int> svi[MAXN];
set<int>::iterator it[MAXN];
int kolko[MAXN], ress;
int main() {
cin>>n>>k>>r;
for (int i=0; i<n; i++)
{
cin>>a[i];
svi[a[i]].insert(i);
}
for (int i=0; i<r; i++)
{
int b, q; cin>>b>>q;
kolko[b]=q;
}
int r=-1;
for (int i=0; i<n; i++) {
if (kolko[i] == 0) continue;
int pom = kolko[i];
it[i] = svi[i].begin();
while (pom-1)
{
//cout<<i<<" "<<*it[i]<<endl;
pom--;
it[i]++;
if (it[i]==svi[i].end()) { cout<<"impossible"; exit(0); }
}
//cout<<i<<" "<<*it[i]<<endl;
r=max(r, *(it[i]));
}
//cout<<"ee "<<r<<endl;
ress=r+1;
for (int i=0; i<n; i++)
{
if (kolko[a[i]]==0) { ress=min(ress, r-i); continue; }
it[a[i]]++;
if (it[a[i]]==svi[a[i]].end()) break;
r=max(r, *(it[a[i]]));
ress=min(ress, r-i);
}
cout<<ress;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Correct |
2 ms |
12636 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
2 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
12632 KB |
Output is correct |
6 |
Correct |
4 ms |
12636 KB |
Output is correct |
7 |
Correct |
3 ms |
12736 KB |
Output is correct |
8 |
Correct |
2 ms |
12636 KB |
Output is correct |
9 |
Correct |
3 ms |
12636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12892 KB |
Output is correct |
2 |
Correct |
3 ms |
12892 KB |
Output is correct |
3 |
Correct |
5 ms |
12892 KB |
Output is correct |
4 |
Correct |
3 ms |
12892 KB |
Output is correct |
5 |
Correct |
3 ms |
12888 KB |
Output is correct |
6 |
Correct |
3 ms |
12888 KB |
Output is correct |
7 |
Correct |
2 ms |
12636 KB |
Output is correct |
8 |
Correct |
2 ms |
12728 KB |
Output is correct |
9 |
Correct |
2 ms |
12636 KB |
Output is correct |
10 |
Correct |
2 ms |
12636 KB |
Output is correct |
11 |
Correct |
3 ms |
12636 KB |
Output is correct |
12 |
Correct |
3 ms |
12636 KB |
Output is correct |
13 |
Correct |
2 ms |
12636 KB |
Output is correct |
14 |
Correct |
2 ms |
12636 KB |
Output is correct |
15 |
Correct |
2 ms |
12636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
22560 KB |
Output is correct |
2 |
Correct |
54 ms |
22356 KB |
Output is correct |
3 |
Correct |
60 ms |
22552 KB |
Output is correct |
4 |
Correct |
56 ms |
22352 KB |
Output is correct |
5 |
Correct |
64 ms |
23124 KB |
Output is correct |
6 |
Correct |
67 ms |
22356 KB |
Output is correct |
7 |
Correct |
70 ms |
22724 KB |
Output is correct |
8 |
Correct |
67 ms |
23380 KB |
Output is correct |
9 |
Correct |
76 ms |
23124 KB |
Output is correct |
10 |
Correct |
62 ms |
22356 KB |
Output is correct |
11 |
Correct |
3 ms |
12892 KB |
Output is correct |
12 |
Correct |
3 ms |
12892 KB |
Output is correct |
13 |
Correct |
4 ms |
12940 KB |
Output is correct |
14 |
Correct |
3 ms |
12892 KB |
Output is correct |
15 |
Correct |
3 ms |
12888 KB |
Output is correct |
16 |
Correct |
3 ms |
12892 KB |
Output is correct |
17 |
Correct |
3 ms |
12636 KB |
Output is correct |
18 |
Correct |
3 ms |
12636 KB |
Output is correct |
19 |
Correct |
3 ms |
12632 KB |
Output is correct |
20 |
Correct |
2 ms |
12636 KB |
Output is correct |
21 |
Correct |
2 ms |
12636 KB |
Output is correct |
22 |
Correct |
2 ms |
12636 KB |
Output is correct |
23 |
Correct |
3 ms |
12736 KB |
Output is correct |
24 |
Correct |
2 ms |
12636 KB |
Output is correct |
25 |
Correct |
3 ms |
12756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
23892 KB |
Output is correct |
2 |
Correct |
92 ms |
23820 KB |
Output is correct |
3 |
Correct |
90 ms |
23568 KB |
Output is correct |
4 |
Correct |
53 ms |
22356 KB |
Output is correct |
5 |
Correct |
99 ms |
24296 KB |
Output is correct |
6 |
Correct |
107 ms |
24316 KB |
Output is correct |
7 |
Correct |
95 ms |
22956 KB |
Output is correct |
8 |
Correct |
78 ms |
23216 KB |
Output is correct |
9 |
Correct |
57 ms |
22436 KB |
Output is correct |
10 |
Correct |
63 ms |
22360 KB |
Output is correct |
11 |
Correct |
60 ms |
22356 KB |
Output is correct |
12 |
Correct |
55 ms |
22352 KB |
Output is correct |
13 |
Correct |
63 ms |
23200 KB |
Output is correct |
14 |
Correct |
59 ms |
22544 KB |
Output is correct |
15 |
Correct |
65 ms |
22644 KB |
Output is correct |
16 |
Correct |
68 ms |
23428 KB |
Output is correct |
17 |
Correct |
84 ms |
23224 KB |
Output is correct |
18 |
Correct |
60 ms |
22340 KB |
Output is correct |
19 |
Correct |
3 ms |
12892 KB |
Output is correct |
20 |
Correct |
3 ms |
12700 KB |
Output is correct |
21 |
Correct |
4 ms |
12892 KB |
Output is correct |
22 |
Correct |
3 ms |
12892 KB |
Output is correct |
23 |
Correct |
3 ms |
12892 KB |
Output is correct |
24 |
Correct |
3 ms |
12892 KB |
Output is correct |
25 |
Correct |
3 ms |
12732 KB |
Output is correct |
26 |
Correct |
2 ms |
12636 KB |
Output is correct |
27 |
Correct |
3 ms |
12636 KB |
Output is correct |
28 |
Correct |
3 ms |
12636 KB |
Output is correct |
29 |
Correct |
2 ms |
12636 KB |
Output is correct |
30 |
Correct |
2 ms |
12636 KB |
Output is correct |
31 |
Correct |
2 ms |
12636 KB |
Output is correct |
32 |
Correct |
2 ms |
12636 KB |
Output is correct |
33 |
Correct |
2 ms |
12632 KB |
Output is correct |