Submission #1121910

#TimeUsernameProblemLanguageResultExecution timeMemory
1121910_callmelucian Martian DNA (BOI18_dna)C++14
100 / 100
24 ms4092 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pl; typedef pair<int,int> pii; typedef tuple<int,int,int> tpl; #define all(a) a.begin(), a.end() #define filter(a) a.erase(unique(all(a)), a.end()) const int mn = 2e5 + 5; int a[mn], delta[mn]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k, r; cin >> n >> k >> r; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 0; i < r; i++) { int b, q; cin >> b >> q; delta[b] = -q; } int start = 0; for (int i = 0; i < k; i++) { while (start + 1 <= n && delta[i] < 0) delta[a[++start]]++; if (delta[i] < 0) return cout << "impossible", 0; } int ans = start; for (int L = 1, R = start; R <= n; R++) { if (R != start) delta[a[R]]++; while (L < R && delta[a[L]] > 0) delta[a[L++]]--; ans = min(ans, R - L + 1); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...