class Solution { public: int maxSubarraySumCircular(vector<int>& A) { int maxsum=INT_MIN; int minsum=INT_MAX; int total=0; int curmax=0; int curmin=0; for(int i=0;i<A.size();i++){ curmax=max(curmax+A[i],A[i]); curmin=min(curmin+A[i],A[i]); maxsum=max(maxsum,curmax); minsum=min(minsum,curmin); total+=A[i]; } return total==minsum?maxsum : max(maxsum,total-minsum); } };