#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,k,r,a[N],cnt[N],mn[N],now=1,ans;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k >> r;
for(int i=1;i<=n;i++) cin >> a[i];
for(int i=0;i<r;i++){
int x,y;
cin >> x >> y;
mn[x]=y;
}
for(int i=0;i<k;i++) while(cnt[i]<mn[i] && now<=n) cnt[a[now++]]++;
for(int i=0;i<k;i++) if(cnt[i]<mn[i]) cout << "imposible",exit(0);
ans=now-1;
for(int i=1;i<=n;i++){
cnt[a[i]]--;
while(cnt[a[i]]<mn[a[i]] && now<=n) cnt[a[now++]]++;
if(cnt[a[i]]<mn[a[i]]) break;
ans=min(ans,now-i-1);
}
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 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 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 |
2392 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 |
2468 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2396 KB |
Output is correct |
2 |
Correct |
9 ms |
2528 KB |
Output is correct |
3 |
Correct |
10 ms |
2396 KB |
Output is correct |
4 |
Correct |
9 ms |
2512 KB |
Output is correct |
5 |
Correct |
13 ms |
2516 KB |
Output is correct |
6 |
Correct |
8 ms |
2396 KB |
Output is correct |
7 |
Incorrect |
9 ms |
2512 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
2772 KB |
Output is correct |
2 |
Correct |
22 ms |
2776 KB |
Output is correct |
3 |
Correct |
15 ms |
2652 KB |
Output is correct |
4 |
Correct |
9 ms |
2516 KB |
Output is correct |
5 |
Incorrect |
23 ms |
2780 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |