You are viewing a single comment's thread. Return to all comments →
What is wrong with this approach?
long maximumSum(vector<long> a, long m) { sort(a.begin(),a.end()); int s=0, end=m-1; long dp[a.size()]={0},i,j; for(i=0;i<a.size();i++){ a[i]=a[i]%m; } dp[0]=a[0]; long large=dp[0]; for(i=1;i<a.size();i++){ dp[i]=max(a[i],(a[i]+dp[i-1])%m); large=max(large,dp[i]); } return large; }
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Subarray Sum
You are viewing a single comment's thread. Return to all comments →
What is wrong with this approach?