Maximum Subarray Sum

  • + 0 comments

    bool myCompare(pair a,pair b){ bool res; if (a.first==b.first) {res=(a.second

    long maximumSum(vector a, long m) { long res=m,sumA=0; vector > vp; vp.push_back(make_pair(sumA,0)); for (uint i=0; i>::iterator itB,itE; long dFirst; int dSecond; for (itB=vp.begin(); itB!=vp.end(); itB++){ itE=itB+1; if (itE==vp.end()) {itE=vp.begin();} dFirst=(m+(*itE).first-(*itB).first)%m; dSecond=(*itE).second-(*itB).second; if (dFirst>0&&dSecond<0) {res=min(res,dFirst);} } return m-res; }