#include <bits/stdc++.h>
using namespace std;
int a[200005], b[200005], c[200005];
vector<int> v[200005];
set<int> s;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k, r, mn;
cin >> n >> k >> r;
for (int i=1; i<=n; i++)
{
cin >> a[i];
v[a[i]].push_back(i);
}
for (int i=1; i<=r; i++)
{
int x, y;
cin >> x >> y;
b[x]=y;
}
for (int i=0; i<k; i++)
{
if (v[i].size()<b[i])
{
cout << "impossible";
return 0;
}
if (b[i])
s.insert(v[i][b[i]-1]);
}
mn=*s.rbegin();
for (int i=1; i<=n; i++)
{
if (b[a[i]])
{
s.erase(v[a[i]][c[a[i]]+b[a[i]]-1]);
if (v[a[i]].size()<=c[a[i]]+b[a[i]])
break;
s.insert(v[a[i]][c[a[i]]+b[a[i]]]);
c[a[i]]++;
}
mn=min(mn, *s.rbegin()-i);
}
cout << mn;
}
Compilation message
dna.cpp: In function 'int main()':
dna.cpp:26:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
26 | if (v[i].size()<b[i])
| ~~~~~~~~~~~^~~~~
dna.cpp:40:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
40 | if (v[a[i]].size()<=c[a[i]]+b[a[i]])
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
5000 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5212 KB |
Output is correct |
2 |
Correct |
2 ms |
5212 KB |
Output is correct |
3 |
Correct |
2 ms |
5284 KB |
Output is correct |
4 |
Correct |
3 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
5208 KB |
Output is correct |
6 |
Correct |
3 ms |
5180 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
3 ms |
4956 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
7512 KB |
Output is correct |
2 |
Correct |
13 ms |
7444 KB |
Output is correct |
3 |
Correct |
16 ms |
7260 KB |
Output is correct |
4 |
Correct |
14 ms |
7516 KB |
Output is correct |
5 |
Correct |
22 ms |
9808 KB |
Output is correct |
6 |
Correct |
9 ms |
7516 KB |
Output is correct |
7 |
Correct |
11 ms |
7444 KB |
Output is correct |
8 |
Correct |
33 ms |
13356 KB |
Output is correct |
9 |
Correct |
18 ms |
8280 KB |
Output is correct |
10 |
Correct |
17 ms |
7416 KB |
Output is correct |
11 |
Correct |
2 ms |
5212 KB |
Output is correct |
12 |
Correct |
2 ms |
5212 KB |
Output is correct |
13 |
Correct |
2 ms |
5212 KB |
Output is correct |
14 |
Correct |
2 ms |
5348 KB |
Output is correct |
15 |
Correct |
3 ms |
5212 KB |
Output is correct |
16 |
Correct |
2 ms |
5212 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
21 |
Correct |
2 ms |
5164 KB |
Output is correct |
22 |
Correct |
2 ms |
4956 KB |
Output is correct |
23 |
Correct |
2 ms |
4956 KB |
Output is correct |
24 |
Correct |
2 ms |
4956 KB |
Output is correct |
25 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
14544 KB |
Output is correct |
2 |
Correct |
57 ms |
12628 KB |
Output is correct |
3 |
Correct |
31 ms |
10584 KB |
Output is correct |
4 |
Correct |
14 ms |
7160 KB |
Output is correct |
5 |
Correct |
31 ms |
11492 KB |
Output is correct |
6 |
Correct |
76 ms |
19928 KB |
Output is correct |
7 |
Correct |
20 ms |
8536 KB |
Output is correct |
8 |
Correct |
47 ms |
9308 KB |
Output is correct |
9 |
Correct |
13 ms |
7516 KB |
Output is correct |
10 |
Correct |
13 ms |
7408 KB |
Output is correct |
11 |
Correct |
18 ms |
7168 KB |
Output is correct |
12 |
Correct |
14 ms |
7516 KB |
Output is correct |
13 |
Correct |
22 ms |
9768 KB |
Output is correct |
14 |
Correct |
10 ms |
7480 KB |
Output is correct |
15 |
Correct |
10 ms |
7516 KB |
Output is correct |
16 |
Correct |
31 ms |
13316 KB |
Output is correct |
17 |
Correct |
19 ms |
8284 KB |
Output is correct |
18 |
Correct |
18 ms |
7416 KB |
Output is correct |
19 |
Correct |
3 ms |
5212 KB |
Output is correct |
20 |
Correct |
2 ms |
5212 KB |
Output is correct |
21 |
Correct |
2 ms |
5212 KB |
Output is correct |
22 |
Correct |
3 ms |
5208 KB |
Output is correct |
23 |
Correct |
2 ms |
5172 KB |
Output is correct |
24 |
Correct |
2 ms |
5212 KB |
Output is correct |
25 |
Correct |
2 ms |
4952 KB |
Output is correct |
26 |
Correct |
2 ms |
4956 KB |
Output is correct |
27 |
Correct |
2 ms |
4956 KB |
Output is correct |
28 |
Correct |
3 ms |
4956 KB |
Output is correct |
29 |
Correct |
2 ms |
4956 KB |
Output is correct |
30 |
Correct |
2 ms |
4956 KB |
Output is correct |
31 |
Correct |
3 ms |
4956 KB |
Output is correct |
32 |
Correct |
2 ms |
4956 KB |
Output is correct |
33 |
Correct |
3 ms |
4956 KB |
Output is correct |