#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define sz(x) (int) (x).size()
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k, r; cin >> n >> k >> r;
int v[200005]={0};
int arr[200005];
for(int i=0; i<n; i++){cin >> arr[i];}
for(int i=0; i<k; i++){v[i]= -97874749478494;}
for(int i=0; i<r; i++){
int a, b; cin >> a >> b;
v[a]= b;
}
int s= 0;
int e= n;
bool yeaa= false;
while(s<e){
int mid= s+ (e-s)/2;
int c[200005]={0};
int count= 0;
for(int i=0; i<mid; i++){
c[arr[i]]++;
if(c[arr[i]]==v[arr[i]]){count++;}
}
bool yea= false;
if(count==r){yea= true;}
for(int i=0; i<n- mid; i++){
if(count==r){yea= true; yeaa= true; break;}
c[arr[i]]--;
if(c[arr[i]]==v[arr[i]]-1){count--;}
c[arr[i+mid]]++;
if(c[arr[i+mid]]==v[arr[i+mid]]){count++;}
}
if(count==r){yea= true; yeaa= true;}
if(yea){e= mid;}
else{s= mid+1;}
}
if(yeaa){cout << e << endl;}
else{cout << "impossible" << endl;}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Incorrect |
3 ms |
4940 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Incorrect |
2 ms |
4940 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
4940 KB |
Output is correct |
2 |
Correct |
24 ms |
5000 KB |
Output is correct |
3 |
Correct |
16 ms |
4940 KB |
Output is correct |
4 |
Correct |
24 ms |
5000 KB |
Output is correct |
5 |
Correct |
31 ms |
4940 KB |
Output is correct |
6 |
Incorrect |
23 ms |
4940 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
4984 KB |
Output is correct |
2 |
Correct |
43 ms |
5000 KB |
Output is correct |
3 |
Correct |
46 ms |
4984 KB |
Output is correct |
4 |
Correct |
13 ms |
5016 KB |
Output is correct |
5 |
Correct |
44 ms |
4940 KB |
Output is correct |
6 |
Correct |
56 ms |
4980 KB |
Output is correct |
7 |
Correct |
30 ms |
4940 KB |
Output is correct |
8 |
Correct |
41 ms |
4992 KB |
Output is correct |
9 |
Correct |
24 ms |
5008 KB |
Output is correct |
10 |
Correct |
28 ms |
4940 KB |
Output is correct |
11 |
Correct |
17 ms |
5004 KB |
Output is correct |
12 |
Correct |
25 ms |
5008 KB |
Output is correct |
13 |
Correct |
34 ms |
4940 KB |
Output is correct |
14 |
Incorrect |
26 ms |
5004 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |