fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int n;
  7. cin>>n;
  8. vector<int>arr(n);
  9. for(int i=0;i<n;i++){
  10. cin>>arr[i];
  11. }
  12. int maxi=0;
  13. for(int i=0;i<n;i++){
  14. unordered_map<int,int>mp;
  15. for(int j=i;j<n;j++){
  16. if(mp.find(arr[j])==mp.end()){
  17. mp[arr[j]]++;
  18. int len=j-i+1;
  19. maxi=max(maxi,len);
  20. }
  21. else{
  22. break;
  23. }
  24. }
  25. }
  26. cout<<"The maximum sum is:"<<maxi;
  27. return 0;
  28. }
Success #stdin #stdout 0s 5324KB
stdin
10
3 2 4 5 2 6 7 8 9 10
stdout
The maximum sum is:8