Didn’t understand the input format of the problem though I’ve implemented the algorithm required to solve this problem correctly.
Code:-
#include<iostream>
using namespace std;
int main() {
int arr[100];
int n;
cin>>n;
int currSum=0;
int maxSum=0;
for(int i=0; i<n; i++){
cin>>arr[i];
}
for(int i=0;i<n;i++){
currSum = currSum + arr[i];
if(currSum < 0){
currSum=0;
}
maxSum=max(currSum,maxSum);
}
cout<<maxSum<<endl;
return 0;
}