<p>You are given a <strong>0-indexed</strong> array <code>nums</code> comprising of <code>n</code> non-negative integers.</p>

<p>In one operation, you must:</p>

<ul>
	<li>Choose an integer <code>i</code> such that <code>1 &lt;= i &lt; n</code> and <code>nums[i] &gt; 0</code>.</li>
	<li>Decrease <code>nums[i]</code> by 1.</li>
	<li>Increase <code>nums[i - 1]</code> by 1.</li>
</ul>

<p>Return<em> the <strong>minimum</strong> possible value of the <strong>maximum</strong> integer of </em><code>nums</code><em> after performing <strong>any</strong> number of operations</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [3,7,1,6]
<strong>Output:</strong> 5
<strong>Explanation:</strong>
One set of optimal operations is as follows:
1. Choose i = 1, and nums becomes [4,6,1,6].
2. Choose i = 3, and nums becomes [4,6,2,5].
3. Choose i = 1, and nums becomes [5,5,2,5].
The maximum integer of nums is 5. It can be shown that the maximum number cannot be less than 5.
Therefore, we return 5.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [10,1]
<strong>Output:</strong> 10
<strong>Explanation:</strong>
It is optimal to leave nums as is, and since 10 is the maximum value, we return 10.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>n == nums.length</code></li>
	<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
	<li><code>0 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
</ul>

class Solution:
    def minimizeArrayValue(self, nums: List[int]) -> int:
        i = 1
        curr_sum = nums[0]
        count = 1
        max_num = 0
        print(math.ceil(2.0))
        sums1 = []

        while i < len(nums):
            if nums[i] >= nums[i - 1]:
                curr_sum = curr_sum + nums[i]
                count = count + 1
                i = i + 1
            else:
                max_num = max(max_num, math.ceil(curr_sum / count))
                sums1.append([curr_sum, math.ceil(curr_sum / count), count])
                curr_sum = nums[i]
                count = 1
                i = i + 1

        max_num = max(max_num, math.ceil(curr_sum / count))
        sums1.append([curr_sum, math.ceil(curr_sum / count), count])

        if len(sums1) == 1:
            return max_num

        def get_avg(sums):
            j = len(sums) - 1
            max_num = 0
            curr_sum = sums[j][0]
            curr_avg = sums[j][1]
            count = sums[j][2]
            sums2 = []
            print(sums)
            while j - 1 >= 0:
                print(sums[j - 1][1], curr_avg)
                if sums[j - 1][1] <= curr_avg:
                    curr_sum = curr_sum + sums[j - 1][0]
                    count = count + sums[j - 1][2]
                    curr_avg = math.ceil(curr_sum / count)
                else:
                    max_num = max(max_num, curr_avg)
                    sums2.append([curr_sum, math.ceil(curr_sum / count), count])
                    curr_sum = sums[j - 1][0]
                    curr_avg = sums[j - 1][1]
                    count = sums[j - 1][2]
                j = j - 1 

            max_num = max(max_num, curr_avg) 
            sums2.append([curr_sum, math.ceil(curr_sum / count), count]) 
            sums2.reverse() 

            return (max_num, sums2)

        prev = None
        curr_sums = sums1
        while True:
            new_max, new_sums = get_avg(curr_sums)
            print(new_max, new_sums)
            if prev != None and prev == new_max:
                break
            prev = new_max
            max_num = new_max
            curr_sums = new_sums

        return max_num
        
656