Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- int niza[n];
- for(int i = 0; i < n; i++) {
- cin >> niza[i];
- }
- int S = 0, E = 0;
- map<int, int> m;
- int najdolga = 0;
- while(E < n) {
- if(m[niza[E]] == 0) {
- m[niza[E]]++;
- E++;
- if(najdolga < E - S) {
- najdolga = E - S;
- }
- }
- else {
- m[niza[S]]--;
- S++;
- }
- }
- cout << najdolga << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement