Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <map>
- using namespace std;
- const int maxn = 1005;
- 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> m;
- int i = 0,j = 0;
- int sum= 0, result = 0;
- while(j < n and i < n) {
- if(m[v[j]] < 1) {
- sum += v[j];
- m[v[j]]++;
- j++;
- }
- else {
- m[v[i]]--;
- sum -= v[i];
- i++;
- }
- result =max(result, sum);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement