Submission #1128864

#TimeUsernameProblemLanguageResultExecution timeMemory
1128864Alihan_8 Martian DNA (BOI18_dna)C++20
100 / 100
97 ms12872 KiB
#include <bits/stdc++.h> using namespace std; signed main(){ int n, k, r; cin >> n >> k >> r; vector <int> d(n); for ( auto &u: d ) cin >> u; vector <int> b(r), q(r); for ( int i = 0; i < r; i++ ){ cin >> b[i] >> q[i]; } vector <vector<int>> p(k); vector <int> it(k, -1); for ( int i = 0; i < n; i++ ) p[d[i]].push_back(i); int mx = 0; for ( int i = 0; i < r; i++ ){ int j = b[i]; if ( (int)p[j].size() < q[i] ) return cout << "impossible\n", 0; it[j] = q[i] - 1; mx = max(mx, p[j][it[j]]); } int opt = mx + 1; for ( int i = 0; i < n; i++ ){ int j = d[i]; if ( it[j] != -1 ){ if ( ++it[j] == (int)p[j].size() ) break; mx = max(mx, p[j][it[j]]); } opt = min(opt, mx - i); } cout << opt << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...