Josif_tepe

Untitled

Dec 3rd, 2025
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     ios_base::sync_with_stdio(false);
  8.     int n, k;
  9.     cin >> n >> k;
  10.    
  11.     vector<int> v(n);
  12.     for(int i = 0; i < n; i++) {
  13.         cin >> v[i];
  14.     }
  15.    
  16.     int res = 0;
  17.     for(int i = 0; i < n; i++) {
  18.        
  19.         int k_cnt = 0;
  20.         vector<int> cnt(k, 0);
  21.         for(int j = i; j < n; j++) {
  22.             if(v[j] < k) {
  23.                 cnt[v[j]]++;
  24.                
  25.                 if(cnt[v[j]] == 3) {
  26.                     k_cnt++;
  27.                 }
  28.                 else if(cnt[v[j]] > 3) {
  29.                     k_cnt--;
  30.                 }
  31.             }
  32.            
  33.            
  34.             if(k_cnt == k) {
  35.                 res = max(res, j - i + 1);
  36.             }
  37.         }
  38.     }
  39.    
  40.     cout << res << endl;
  41.     return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment