Advertisement
Josif_tepe

Untitled

Mar 10th, 2023
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     cin >> n;
  8.    
  9.     int niza[n];
  10.     for(int i = 0; i < n; i++) {
  11.         cin >> niza[i];
  12.     }
  13.    
  14.     int S = 0, E = 0;
  15.     map<int, int> m;
  16.     int najdolga = 0;
  17.     while(E < n) {
  18.         if(m[niza[E]] == 0) {
  19.             m[niza[E]]++;
  20.            
  21.             E++;
  22.             if(najdolga < E - S) {
  23.                 najdolga = E - S;
  24.             }
  25.         }
  26.         else {
  27.             m[niza[S]]--;
  28.             S++;
  29.         }
  30.     }
  31.     cout << najdolga << endl;
  32.     return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement