이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
using ll = long long;
#define int ll
const int mod = 1e9+7;
void solve(int tc) {
int n, k, r;
cin >> n >> k >> r;
vector<int> v(n);
for (auto &x : v) cin >> x;
vector<int> a(k);
int req = 0;
for (int i = 0; i < r; ++i) {
int x, y;
cin >> x >> y;
a[x] += y;
req += y;
}
if (a[v[0]] >0) --req;
a[v[0]]--;
int l = 0;
r = 0;
int ans = mod;
while (r < n-1) {
while (req == 0) {
ans = min(ans, r-l+1);
if (a[v[l]] >= 0) req++;
a[v[l]]++;
}
while (req > 0 and r+1 < n) {
++r;
if (a[v[r]] > 0) --req;
a[v[r]]--;
}
if (req == 0) ans = min(ans, r-l+1);
}
if (ans >= mod) cout << "impossible\n";
cout << ans << '\n';
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int tc = 1;
//cin >> tc;
for (int i = 1; i <= tc; ++i) solve(i);
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... |