Пример #1
0
 public void Update(int arrMin, int arrValue, int arrIndex)
 {
     currSum = currSum + arrValue;
     if (child != null)
     {
         child.Update(arrMin, arrValue, arrIndex);
     }
     if (arrValue > 0)
     {
         if (currSum >= maxSum)
         {
             maxSum = currSum;
         }
         if (child == null && isReadyForChild)
         {
             child           = new ArrValue(arrMin, arrValue, arrIndex);
             isReadyForChild = false;
         }
     }
     else
     {
         interMediateMax.Add(currSum - arrValue);
         isReadyForChild = true;
     }
 }
Пример #2
0
        public int getMaxSubSumLong(int[] arr)
        {
            if (arr.Length == 0)
            {
                return(0);
            }
            var arrMin = arr.Min();

            ArrValue leftArrValue = null;

            for (int i = 0; i < arr.Length; i++)
            {
                if (leftArrValue == null)
                {
                    if (arr[i] > 0)
                    {
                        leftArrValue = new ArrValue(arrMin, arr[i], i);
                    }
                }
                else
                {
                    leftArrValue.Update(arrMin, arr[i], i);
                }
            }

            int sum = 0;

            if (leftArrValue == null)
            {
                return(0);
            }
            leftArrValue.SetMax(ref sum);



            return(sum);
        }