이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
const int INF = 1e9;
const int MAXN = 2e5 + 5;
const ll LINF = 1e18;
const double pi = acos(-1);
const double EPS = 1e-9;
template <class T> using MinPQ = priority_queue<T, vector<T>, greater<T>>;
template <class T> using MaxPQ = priority_queue<T>;
int n, k, r;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> k >> r;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
vector<int> q(k);
int numOfMatched = k - r;
for (int i = 0; i < r; i++) {
int b;
cin >> b;
cin >> q[b];
}
int j = 0;
vector<int> matched(k, 0);
int ans = 1e9;
int curLen = 0;
for (int i = 0; i < n; i++) {
matched[a[i]]++; ++curLen;
if (matched[a[i]] == q[a[i]]) ++numOfMatched;
if (numOfMatched == k) ans = min(ans, curLen);
while (j <= i && numOfMatched == k) {
matched[a[j]]--;
if (matched[a[j]] < q[a[j]]) numOfMatched--;
j++;
curLen--;
if (numOfMatched == k) ans = min(ans, curLen);
}
}
if (ans > n) cout << "impossible\n";
else cout << ans << "\n";
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... |