제출 #554563

#제출 시각아이디문제언어결과실행 시간메모리
554563Soumya1 Martian DNA (BOI18_dna)C++17
100 / 100
34 ms3788 KiB
#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
const int mxN = 2e5 + 5;
int a[mxN];
int cnt[mxN];
void testCase() {
  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 a, b;
    cin >> a >> b;
    cnt[a] = b;
  }
  int cc = r;
  int ptr = 1;
  int ans = n + 1;
  for (int i = 1; i <= n; i++) {
    while (ptr <= n && cc) {
      cnt[a[ptr]]--;
      if (cnt[a[ptr]] == 0) cc--;
      ptr++;
    }
    if (!cc) ans = min(ans, ptr - i);
    cnt[a[i]]++;
    if (cnt[a[i]] == 1) cc++;
  }
  if (ans == n + 1) cout << "impossible\n";
  else cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  testCase();
  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...