Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- using namespace std;
- int main() {
- int n, k, m;
- cin >> n >> k >> m;
- vector<int> v(n);
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- }
- vector<int> req(k + 1, 0);
- for(int i = 0; i < m; i++) {
- int a, b;
- cin >> a >> b;
- req[a] = b;
- }
- int j = 0;
- int cnt = m;
- int res = 2e9;
- for(int i = 0; i < n; i++) {
- while(cnt > 0 and j < n) {
- req[v[j]]--;
- if(req[v[j]] == 0) {
- cnt--;
- }
- j++;
- }
- if(cnt == 0) {
- res = min(res, j - i);
- }
- req[v[i]]++;
- if(req[v[i]] > 0) {
- cnt++;
- }
- }
- if(res == 2e9) {
- cout << "impossible" << endl;
- }
- else {
- cout << res << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement