#include <iostream>
#include <vector>
using namespace std;
int main() {
    vector<int> v={-2, 1, -3, 4, -1, 2, 1, -5, 4};
    int start=-1, end=-1, temp=-1, sum=0, maxSum=-1;
    for(int i=0; i<v.size(); i++){
        if(sum==0)
            temp=i;
        sum+=v[i];
        if(sum>maxSum){
            maxSum=sum;
            start=temp;
            end=i;
        }
        if(sum<0)
            sum=0;
    }
    cout<<start<<" "<<end<<" "<<maxSum<<"\n";
    cout<<"Maximum Sum subarray: \n";
    for(int i=start; i<=end; i++){
        cout<<v[i]<<" ";
    }
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: