Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <map>
- using namespace std;
- const int INF = 2e9;
- int main() {
- ios_base::sync_with_stdio(false);
- int n;
- cin >> n;
- vector<int> v(n);
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- }
- map<int, int> cnt;
- int i = 0, j = 0;
- int res = 0;
- while(j < n) {
- if(cnt[v[j]] == 0) {
- cnt[v[j]]++;
- res = max(res, j - i + 1);
- j++;
- }
- else {
- cnt[v[i]]--;
- i++;
- }
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment