이 제출은 이전 버전의 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;
const int mod = 1e9+7;
void solve(int tc) {
int n, k, r;
cin >> n >> k >> r;
vector<int> v(n), a(k);
vector<bool> need(k);
for (auto &x : v) cin >> x;
int req = 0;
while (r--) {
int b, q;
cin >> b >> q;
a[b] = q;
req += q;
need[b] = true;
}
int l = 0;
r = 0;
if (need[v[0]]) {
--req;
}
--a[v[0]];
int ans = 1e9, cmp = 1e9;
while (r < n-1) {
while (!req) {
// cout << "l r : " << l << " " << r << '\n';
ans = min(ans, r-l+1);
if (need[v[l]]) {
// cout << "v[l] a[v[l]] : " << v[l] << " " << a[v[l]] << '\n';
if (a[v[l]] >= 0) req++;
}
a[v[l]]++;
++l;
}
while (req and r < n) {
++r;
if (need[v[r]]) {
// cout << "v[r] a[v[r]] " << v[r] << " " << a[v[r]] << '\n';
if (a[v[r]] > 0) --req;
// cout << "a[v[r]] : " << a[v[r]] << '\n';
}
a[v[r]]--;
}
}
if (ans == cmp) cout << "impossible\n";
else 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... |