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 MAXN = 2e5+10;
typedef pair<int,int> pii;
#define pb push_back
#define f first
#define s second
int n, k, r, a, b, resp = MAXN;
vector<int> num[MAXN];
vector<pii> query;
int main () {
cin >> n >> k >> r;
for(int i = 1; i <= n; i++) {
cin >> a;
num[a].pb(i);
}
while(r--) {
cin >> a >> b;
query.pb({a, b});
}
for(int i = 1; i <= n; i++) {
int fim = 0;
for(auto it : query) {
auto ptr = lower_bound(num[it.f].begin(), num[it.f].end(), i);
ptr += it.s - 1;
if(ptr>=num[it.f].end()) { fim = -1; break; }
fim = max(fim, *ptr);
}
if(fim==-1) break;
resp = min(resp, fim-i+1);
}
if(resp == MAXN) cout << "impossible\n";
else cout << resp << 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... |