#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define ll long long
#define int long long
const long long inf=1e18;
const int MOD=998244353;
const int N=3e5+5;
int req[N],am[N];
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,k,r; cin>>n>>k>>r;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
set<int> bad;
for(int i=0;i<r;i++){
int x,y; cin>>x>>y;
bad.insert(x);
req[x]=y;
}
int ans=inf,l=0;
for(int i=0;i<n;i++){
am[a[i]]++;
if(am[a[i]]==req[a[i]]){
bad.erase(a[i]);
}
while(bad.size()==0){
if(am[a[l]]<=req[a[l]])break;
am[a[l]]--;
l++;
}
if(bad.size()==0){
ans=min(ans,i-l+1);
}
}
if(ans==inf)cout<<"impossible";
else cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2400 KB |
Output is correct |
14 |
Correct |
1 ms |
2400 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
4068 KB |
Output is correct |
2 |
Correct |
10 ms |
3932 KB |
Output is correct |
3 |
Correct |
12 ms |
3936 KB |
Output is correct |
4 |
Correct |
10 ms |
4072 KB |
Output is correct |
5 |
Correct |
12 ms |
4584 KB |
Output is correct |
6 |
Correct |
10 ms |
3936 KB |
Output is correct |
7 |
Correct |
8 ms |
4072 KB |
Output is correct |
8 |
Correct |
14 ms |
5468 KB |
Output is correct |
9 |
Correct |
12 ms |
3936 KB |
Output is correct |
10 |
Correct |
9 ms |
4076 KB |
Output is correct |
11 |
Correct |
1 ms |
2404 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
0 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
0 ms |
2392 KB |
Output is correct |
25 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
8272 KB |
Output is correct |
2 |
Correct |
42 ms |
7252 KB |
Output is correct |
3 |
Correct |
20 ms |
5464 KB |
Output is correct |
4 |
Correct |
8 ms |
4084 KB |
Output is correct |
5 |
Correct |
34 ms |
8536 KB |
Output is correct |
6 |
Correct |
62 ms |
10032 KB |
Output is correct |
7 |
Correct |
13 ms |
4440 KB |
Output is correct |
8 |
Correct |
17 ms |
4832 KB |
Output is correct |
9 |
Correct |
7 ms |
3932 KB |
Output is correct |
10 |
Correct |
8 ms |
3932 KB |
Output is correct |
11 |
Correct |
9 ms |
4068 KB |
Output is correct |
12 |
Correct |
8 ms |
4072 KB |
Output is correct |
13 |
Correct |
11 ms |
4700 KB |
Output is correct |
14 |
Correct |
7 ms |
4076 KB |
Output is correct |
15 |
Correct |
8 ms |
3932 KB |
Output is correct |
16 |
Correct |
13 ms |
5468 KB |
Output is correct |
17 |
Correct |
11 ms |
4072 KB |
Output is correct |
18 |
Correct |
8 ms |
3932 KB |
Output is correct |
19 |
Correct |
1 ms |
2500 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
0 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
0 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
0 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
0 ms |
2396 KB |
Output is correct |
33 |
Correct |
0 ms |
2396 KB |
Output is correct |