58 00nlogn 59 Int Max3 Int Int B Int C 60 Return B C C Bc B C 61 62 63 Int Maxsumrec Const Q43888359
Please change code such that the indicies of the max subarrayis also returned. thanks!!
58 //00nlogn) 59 int max3(int a, int b, int c) { 60 return a>b ? a>c ? a : c: bc ? b:c; 61 } 62 63 int maxSumRec(const vector int>& a, int left, int right) { 64 if(left == right) if(a[left] > 0) return a[left]; else return 0; int center = (left+right)/2; int maxLeft Sum = maxSumRec(a, left, center); int maxRight Sum = maxSumRecca, center+1, right); int start = , end = 0; int maxLeft BorderSum = 0, leftBorderSum = 0; for(int i = center; i >= left; – i) { leftBorderSum + a[i]; if(leftBorderSum > maxLeftBorderSum) { end = i; maxLeftBorderSum = leftBorderSum; int maxRightBorderSum = 0, rightBorderSum ; for(int j = center+1; j<-right; ++i) rightBorderSum += a[j]; if(rightBorderSum > maxRightBorderSum) { start = j; maxRightBorderSum = rightBorderSum; 94 return max3 (maxLeftSum, maxRight Sum, maxLeft BorderSum + maxRightBorderSum); 95 ) 96 97 void maxSubSum3(const vector int>& a) { 98 cout<<“max sum=”<<maxSumRec(a, e, a.size()-1)<<endl; 99 } 100 101 : 102 //0(n) 102 vaid mave…mi Show transcribed image text 58 //00nlogn) 59 int max3(int a, int b, int c) { 60 return a>b ? a>c ? a : c: bc ? b:c; 61 } 62 63 int maxSumRec(const vector int>& a, int left, int right) { 64 if(left == right) if(a[left] > 0) return a[left]; else return 0; int center = (left+right)/2; int maxLeft Sum = maxSumRec(a, left, center); int maxRight Sum = maxSumRecca, center+1, right); int start = , end = 0; int maxLeft BorderSum = 0, leftBorderSum = 0; for(int i = center; i >= left; – i) { leftBorderSum + a[i]; if(leftBorderSum > maxLeftBorderSum) { end = i; maxLeftBorderSum = leftBorderSum; int maxRightBorderSum = 0, rightBorderSum ; for(int j = center+1; j maxRightBorderSum) { start = j; maxRightBorderSum = rightBorderSum; 94 return max3 (maxLeftSum, maxRight Sum, maxLeft BorderSum + maxRightBorderSum); 95 ) 96 97 void maxSubSum3(const vector int>& a) { 98 cout
Expert Answer
Answer to 58 //00nlogn) 59 int max3(int a, int b, int c) { 60 return a>b ? a>c ? a : c: bc ? b:c; 61 } 62 63 int maxSumRec(const v…
OR