This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int maxn5 = 3e5 + 10;
int a[maxn5], req[maxn5];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n, k, r;
cin >> n >> k >> r;
for(int i = 0; i < n; i++)
cin >> a[i];
for(int i = 0; i < r; i++){
int a, b; cin >> a >> b;
req[a] = b;
}
int id = 0;
req[a[0]]--;
int rem = r, ans = n + 10;
if(req[a[0]] == 0)
rem--;
for(int i = 0; i < n; i++){
while(rem && id < n - 1){
id++;
req[a[id]]--;
if(req[a[id]] == 0)
rem--;
}
if(rem == 0)
ans = min(ans, id - i + 1);
req[a[i]]++;
if(req[a[i]] == 1)
rem++;
if(id == i){
id++;
req[a[id]]--;
if(req[a[id]] == 0)
rem--;
}
}
if(ans > n)
cout << "impossible" << endl;
else
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |