#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
n=8; //size of array
int arr[] ={-2,-3,4,-1,-2,1,5,-3};
int best= 0, sum =0;
for(int i=0;i<n;i++){
sum = max(arr[i],sum+ arr[i]); // max of array
best= max(best,sum); // Largest sum of subarray
}
cout<< best<<"\n";
return 0;
}
No comments:
Post a Comment