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 <iostream>
//#include <bits/stdc++.h>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef vector<ll> vi;
typedef vector<bool> vb;
const ll mm = 1000000007;
const int maxn = 2e5 + 1;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
ll n, k, r; cin >> n >> k >> r;
vi a(n), kb(n);
map<ll, ll> g;
vb b(r);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < r; i++) {
ll x, y; cin >> x >> y;
g[x] = y;
}
ll rez = n+1, brojdobrih=0;
ll st = 0,end=0;
ll p = a[end];
kb[p]++;
if (kb[p] == g[p]) {
brojdobrih++;
}
while (st<n) {
/*
cout << "STANJE" << endl;
cout << "st i end:" << st << " i " << end << endl;
cout << "brojdobrih: " << brojdobrih << endl;
for (auto x : kb) cout << x << " ";
cout << endl << endl;*/
if (brojdobrih < r) {
if (end == n - 1) { //
st = n;
}
else {
end++;
ll p = a[end];
kb[p]++;
if (kb[p] == g[p]) {
brojdobrih++;
}
}
}
else {
//cout << "jupi!" << endl;
rez = min(rez, end - st + 1);
ll p = a[st];
kb[p]--;
if (g[p] == 0) {
//:)
}
else if(kb[p]<g[p]){
brojdobrih--;
}
st++;
}
}
if (rez == n + 1) cout << "impossible" << endl;
else cout << rez << endl;
return 0;
}
| # | 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... |