Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main() {
- int n, k;
- cin >> n >> k;
- vector<int> a(n);
- cin >> a;
- vector<int> qa(k + 1);
- int cnt = 0, i = 0, j = n;
- for (int l = 0, r = 0; l < n; ++l) {
- while (r < n && cnt < k) {
- if (!qa[a[r]]) ++cnt;
- qa[a[r]]++;
- ++r;
- }
- if (cnt == k && r - l < j - i) {
- i = l, j = r;
- }
- qa[a[l]]--;
- if (qa[a[l]] == 0) --cnt;
- }
- cout << i + 1 << " " << j << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement