#include <bits/stdc++.h>
using namespace std;
int m,q,n,ans,l,r,u,v,ct[200005],now[200005],ok,a[200005];
int main(){
ios::sync_with_stdio(false);
cin >> n >> m >> q;
for (int i=1;i<=n;i++){
cin >> a[i];
}
for (int i=1;i<=q;i++){
cin >> u >> v;
ct[u]=v;
}
l=1; r=0; ans=1e9;
while (l <= n && r <= n){
if (ok == q){
ans=min(ans,r-l+1);
if (now[a[l]] == ct[a[l]])
ok--;
now[a[l]]--;
l++;
}
else
{
r++;
now[a[r]]++;
if (now[a[r]] == ct[a[r]])
ok++;
}
}
if (ans == 1e9)
cout << "impossible\n";
else
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1516 KB |
Output is correct |
2 |
Correct |
16 ms |
1516 KB |
Output is correct |
3 |
Correct |
17 ms |
1644 KB |
Output is correct |
4 |
Correct |
16 ms |
1516 KB |
Output is correct |
5 |
Correct |
21 ms |
2688 KB |
Output is correct |
6 |
Correct |
15 ms |
1516 KB |
Output is correct |
7 |
Correct |
15 ms |
1764 KB |
Output is correct |
8 |
Correct |
23 ms |
3200 KB |
Output is correct |
9 |
Correct |
19 ms |
2156 KB |
Output is correct |
10 |
Correct |
17 ms |
1516 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
3536 KB |
Output is correct |
2 |
Correct |
31 ms |
3200 KB |
Output is correct |
3 |
Correct |
25 ms |
2796 KB |
Output is correct |
4 |
Correct |
15 ms |
1516 KB |
Output is correct |
5 |
Correct |
36 ms |
4076 KB |
Output is correct |
6 |
Correct |
41 ms |
4608 KB |
Output is correct |
7 |
Correct |
20 ms |
2156 KB |
Output is correct |
8 |
Correct |
23 ms |
2540 KB |
Output is correct |
9 |
Correct |
15 ms |
1516 KB |
Output is correct |
10 |
Correct |
16 ms |
1516 KB |
Output is correct |
11 |
Correct |
17 ms |
1516 KB |
Output is correct |
12 |
Correct |
16 ms |
1516 KB |
Output is correct |
13 |
Correct |
21 ms |
2668 KB |
Output is correct |
14 |
Correct |
15 ms |
1516 KB |
Output is correct |
15 |
Correct |
15 ms |
1772 KB |
Output is correct |
16 |
Correct |
23 ms |
3180 KB |
Output is correct |
17 |
Correct |
19 ms |
2156 KB |
Output is correct |
18 |
Correct |
16 ms |
1516 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |