#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
#define pii pair<int, int>
#define ll long long
int v[maxn], need[maxn];
map<int, int> mp;
int main(){
int n, k, m; cin >> n >> k >> m;
for(int i = 0; i < n; i++) cin >> v[i];
for(int i = 0; i < m; i++){
int a, b; cin >> a >> b;
need[a] = b;
}
int l = 0, r = 0;
int ans = n+1;
while(l<n){
int invalid_cnt = m;
bool term = false;
while(invalid_cnt){
if(r==n) {term = true; break;}
mp[v[r]]++;
if(mp[v[r]]==need[v[r]]) invalid_cnt--;
r++;
}
if(term==true) break;
while(true){
if(mp[v[l]]==need[v[l]]) break;
mp[v[l]]--;
l++;
}
ans = min(ans, r-l);
}
if(ans == n+1) cout << "impossible\n";
else cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
1068 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
178 ms |
5208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |