#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n,k,r; cin>>n>>k>>r;
int arr[n];
map<int,int>m;
map<int,int>req;
set<int>s;
for(int i=0; i<n; i++) cin>>arr[i];
for(int i=0; i<r; i++){
int a,b; cin>>a>>b;
req[a]=b;
s.insert(a);
}
int st=0,ans=LLONG_MAX;
for(int i=0; i<n; i++){
if(req.find(arr[i])!=req.end()) m[arr[i]]++;
if(m[arr[i]]>=req[arr[i]] and s.find(arr[i])!=s.end()) s.erase(arr[i]);
while(s.empty()){
ans=min(ans,i-st+1);
if(req.find(arr[st])!=req.end()){
m[arr[st]]--;
if(m[arr[st]]<req[arr[st]]) s.insert(arr[st]);
}
st++;
}
}
if(ans==LLONG_MAX) cout<<"impossible";
else cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
2380 KB |
Output is correct |
2 |
Correct |
14 ms |
2408 KB |
Output is correct |
3 |
Correct |
23 ms |
2448 KB |
Output is correct |
4 |
Correct |
20 ms |
2396 KB |
Output is correct |
5 |
Incorrect |
141 ms |
13000 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
263 ms |
17540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |