Josif_tepe

Untitled

Dec 3rd, 2025
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 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.         for(int j = i; j < n; j++) {
  19.             vector<int> cnt(k, 0);
  20.            
  21.             for(int l = i; l <= j; l++) {
  22.                 if(v[l] < k) {
  23.                     cnt[v[l]]++;
  24.                 }
  25.             }
  26.            
  27.             bool ok = true;
  28.             for(int l = 0; l < k; l++) {
  29.                 if(cnt[l] != 3) {
  30.                     ok = false;
  31.                     break;
  32.                 }
  33.             }
  34.             if(ok) {
  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