Easily understandable code


#1

#define ll long long int
vector Solution::maxset(vector &A) {
int n=A.size();
ll sum=0;ll t=0;int start=-1;int end=-1;int j=0;int l=0;int gl=0;
for(int i=0;i<n;++i){

    if(A[i]>=0){
        
        t=0;l=0;
        j=i;
        while(i<n&&A[i]>=0){
            t+=A[i];l++;i++;
        }
        // cout<<"<"<<t<<">";
        if(sum==t){
            if(gl<l){
                
                start=j;
                end=i-1;
                gl=l;
            }  
        }
        
        else 
        {   
            if(sum<t){
                if(gl<l)gl=l;
                sum=t;
                start=j;
                end=i-1;
            }
        }
    }
}
vector<int>a;
if(gl){
    for(int i=start;i<=end;++i)
        a.push_back(A[i]);
}
return a; 
}