Max sum of subset
// Online C++ compiler to run C++ program online
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int max_sum(int*arr, int n){
int m=0;
int sum=0;
for(int i=0;i<n;i++){
sum=sum+arr[i];
m=max(sum,m);
sum=m;
}
return m;
}
int main() {
int arr[10]={2,3,-8,7,-1,3,2};
int n=8;
cout<<max_sum(arr,n);
return 0;
}
Comments
Post a Comment