#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n,k,r;
cin>>n>>k>>r;
int a[n];
set<int>st[k];
for(int i=0;i<k;i++){
st[i].insert(n);
}
for(int i=0;i<n;i++){
cin>>a[i];
st[a[i]].insert(i);
}
vector<bool>need(k,0);
int b[r],q[r];
int R=0;
for(int i=0;i<r;i++){
cin>>b[i]>>q[i];
need[b[i]]=true;
if((int)st[b[i]].size()-1<q[i]){
cout<<"impossible";
return 0;
}
q[i]--;
R=max(R,*st[b[i]].begin());
while(q[i]--){
st[b[i]].erase(st[b[i]].begin());
R=max(R,*st[b[i]].begin());
}
}
int ans=n;
for(int i=0;i<n;i++){
if(R<n) ans=min(ans,R-i+1);
if(need[a[i]]==true){
if(!st[a[i]].empty()) st[a[i]].erase(st[a[i]].begin());
if(!st[a[i]].empty()) R=max(R,*st[a[i]].begin());
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
452 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
888 KB |
Output is correct |
4 |
Correct |
1 ms |
984 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
10540 KB |
Output is correct |
2 |
Correct |
41 ms |
10860 KB |
Output is correct |
3 |
Correct |
47 ms |
11040 KB |
Output is correct |
4 |
Correct |
39 ms |
11012 KB |
Output is correct |
5 |
Correct |
47 ms |
19248 KB |
Output is correct |
6 |
Correct |
49 ms |
10836 KB |
Output is correct |
7 |
Correct |
48 ms |
11100 KB |
Output is correct |
8 |
Correct |
84 ms |
30548 KB |
Output is correct |
9 |
Correct |
47 ms |
12112 KB |
Output is correct |
10 |
Correct |
55 ms |
10928 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
880 KB |
Output is correct |
14 |
Correct |
1 ms |
860 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
18512 KB |
Output is correct |
2 |
Correct |
54 ms |
16468 KB |
Output is correct |
3 |
Correct |
56 ms |
16212 KB |
Output is correct |
4 |
Correct |
36 ms |
10556 KB |
Output is correct |
5 |
Correct |
73 ms |
20604 KB |
Output is correct |
6 |
Correct |
122 ms |
28244 KB |
Output is correct |
7 |
Correct |
63 ms |
12368 KB |
Output is correct |
8 |
Correct |
65 ms |
13784 KB |
Output is correct |
9 |
Correct |
39 ms |
10832 KB |
Output is correct |
10 |
Correct |
38 ms |
10836 KB |
Output is correct |
11 |
Correct |
46 ms |
10832 KB |
Output is correct |
12 |
Correct |
46 ms |
10876 KB |
Output is correct |
13 |
Correct |
60 ms |
19272 KB |
Output is correct |
14 |
Correct |
43 ms |
10996 KB |
Output is correct |
15 |
Correct |
53 ms |
11120 KB |
Output is correct |
16 |
Correct |
97 ms |
30556 KB |
Output is correct |
17 |
Correct |
51 ms |
12112 KB |
Output is correct |
18 |
Correct |
42 ms |
10844 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
860 KB |
Output is correct |
22 |
Correct |
1 ms |
860 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
412 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |