#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=2e5+10,P=998244353;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
int n,k,r;
int dna[MAX];
int cnt[MAX];
int req[MAX];
int main() {
speed;
cin>>n>>k>>r;
for (int i=1;i<=n;i++) {
cin>>dna[i];
}
memset(cnt,0,sizeof(cnt));
memset(req,0,sizeof(req));
for (int i=0;i<r;i++) {
int b,q;
cin>>b>>q;
req[b]=q;
}
int ttl=n-r;
int ans=INF;
int l=1;
for (int r=1;r<=n;r++) {
cnt[dna[r]]++;
if (cnt[dna[r]]==req[dna[r]]) ttl++;
if (ttl<n) continue;
while (cnt[dna[l]]!=req[dna[l]]) {
cnt[dna[l]]--;
l++;
}
ans=min(r-l+1,ans);
}
if (ans==INF) cout<<"impossible\n";
else cout<<ans<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2904 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2800 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
3164 KB |
Output is correct |
2 |
Correct |
10 ms |
3164 KB |
Output is correct |
3 |
Correct |
10 ms |
3164 KB |
Output is correct |
4 |
Correct |
10 ms |
3076 KB |
Output is correct |
5 |
Correct |
15 ms |
3924 KB |
Output is correct |
6 |
Correct |
8 ms |
3164 KB |
Output is correct |
7 |
Correct |
9 ms |
3164 KB |
Output is correct |
8 |
Correct |
15 ms |
3932 KB |
Output is correct |
9 |
Correct |
12 ms |
3676 KB |
Output is correct |
10 |
Correct |
9 ms |
3164 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2512 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2904 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
4692 KB |
Output is correct |
2 |
Correct |
19 ms |
4184 KB |
Output is correct |
3 |
Correct |
15 ms |
3932 KB |
Output is correct |
4 |
Correct |
9 ms |
3164 KB |
Output is correct |
5 |
Correct |
21 ms |
4956 KB |
Output is correct |
6 |
Correct |
27 ms |
4676 KB |
Output is correct |
7 |
Correct |
12 ms |
3676 KB |
Output is correct |
8 |
Correct |
15 ms |
3932 KB |
Output is correct |
9 |
Correct |
9 ms |
3164 KB |
Output is correct |
10 |
Correct |
10 ms |
3164 KB |
Output is correct |
11 |
Correct |
10 ms |
3160 KB |
Output is correct |
12 |
Correct |
9 ms |
3160 KB |
Output is correct |
13 |
Correct |
12 ms |
3932 KB |
Output is correct |
14 |
Correct |
9 ms |
3164 KB |
Output is correct |
15 |
Correct |
10 ms |
3268 KB |
Output is correct |
16 |
Correct |
15 ms |
3932 KB |
Output is correct |
17 |
Correct |
12 ms |
3676 KB |
Output is correct |
18 |
Correct |
11 ms |
3164 KB |
Output is correct |
19 |
Correct |
1 ms |
2648 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
1 ms |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
1 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
2656 KB |
Output is correct |
33 |
Correct |
1 ms |
2656 KB |
Output is correct |