#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5,inf=1e9;
int a[N],mn[N],cnt[N];
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,k,R;
cin>>n>>k>>R;
for (int i = 1; i <= n; i++){
cin>>a[i];
}
for (int i = 1; i <= k; i++) mn[i] = inf;
for (int i = 1; i <= R; i++){
int x,y;
cin>>x>>y;
mn[x] = y;
}
int C = R,r = 1,ans=inf;
cnt[a[1]]++;
if (cnt[a[1]] >= mn[a[1]]) --C;
for (int i = 1; i <= n; i++){
while (C > 0 && r + 1 <= n){
++r;
cnt[a[r]]++;
if (cnt[a[r]] - 1 < mn[a[r]] && cnt[a[r]] >= mn[a[r]])
C--;
}
if (C == 0) ans=min(ans,r - i + 1);
int dl = 0;
if (cnt[a[i]] >= mn[a[i]]) ++dl;
cnt[a[i]]--;
if (cnt[a[i]] >= mn[a[i]]) --dl;
C -= dl;
}
if(ans==inf) cout<<"impossible";
else cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
1112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
1672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |