Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS_
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <cmath>
- #include <string>
- #define sz(a) int(a.size())
- #define all(a) a.begin(), a.end()
- #define fore(i, l, r) for(int i = int(l); i < int(r); i++)
- #define forn(i, n) fore(i, 0, n)
- #define pb push_back
- #define x first
- #define y second
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- //#ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- //#endif
- int n,k;
- cin >> n >> k;
- vector <int> cnt(27);
- vector <int> a(n);
- forn(i,n) {
- cin >> a[i];
- }
- int kol = 0;
- int l = 0;
- int r = -1;
- forn(i,n) {
- if (kol == k) {
- break;
- }
- if (cnt[a[i]] == 0) {
- kol++;
- }
- cnt[a[i]]++;
- r = i + 1;
- }
- if (kol < k) {
- cout << n;
- return 0;
- }
- int ans = r - l;
- int cnt_ans = 1;
- while (r < n) {
- if (cnt[a[r]] == 0) {
- kol++;
- while (kol > k) {
- if (cnt[a[l]] == 1) {
- kol--;
- }
- cnt[a[l]]--;
- l++;
- }
- }
- cnt[a[r]]++;
- r++;
- if (r - l > ans) {
- ans = r - l;
- cnt_ans = 1;
- }
- else if (r - l == ans) {
- cnt_ans++;
- }
- }
- if (r - l > ans) {
- ans = r - l;
- cnt_ans = 1;
- }
- else if (r - l == ans) {
- cnt_ans++;
- }
- cout << ans << " " << cnt_ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement