Advertisement
tuki2501

dna.cpp

Feb 9th, 2022
1,028
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.   int n, k, r;
  6.   cin >> n >> k >> r;
  7.   vector<int> a(n);
  8.   for (auto &i : a) {
  9.     cin >> i;
  10.   }
  11.   vector<int> mem(k);
  12.   for (int i = 0; i < r; i++) {
  13.     int b, q;
  14.     cin >> b >> q;
  15.     mem[b] = q;
  16.   }
  17.   int i = 0, d = 0;
  18.   vector<int> cnt(k);
  19.   while (i < n) {
  20.     cnt[a[i]]++;
  21.     if (mem[a[i]] && cnt[a[i]] == mem[a[i]]) d++;
  22.     if (d == r) break;
  23.     i++;
  24.   }
  25.   if (i == n) {
  26.     cout << "impossible" << '\n';
  27.     return 0;
  28.   }
  29.   int ans = i + 1, j = 0;
  30.   while (i < n) {
  31.     while (!(mem[a[j]] && cnt[a[j]] == mem[a[j]])) {
  32.       cnt[a[j]]--;
  33.       j++;
  34.     }
  35.     ans = min(ans, i - j + 1);
  36.     i++;
  37.     cnt[a[i]]++;
  38.   }
  39.   cout << ans << '\n';
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement