# Max Array Sum

By
blackntt

# Problem

Link mô tả: https://www.hackerrank.com/challenges/max-array-sum/problem

# Solution

// Complete the maxSubsetSum function below.
int maxSubsetSum(vector<int> arr) {
    vector<long> maxArr(arr.size(),0);
    maxArr[0]=arr[0]>0?arr[0]:0;
    maxArr[1]= arr[1]>maxArr[0]? arr[1]:maxArr[0];
    for(size_t i=2;i<arr.size();i++){
        if(arr[i]+maxArr[i-2]>maxArr[i-1]){
            maxArr[i]=arr[i]+maxArr[i-2];
        }else{
            maxArr[i]=maxArr[i-1];
        }
    }
    return maxArr[arr.size()-1];

}