classSolution { public: intminimizeArrayValue(vector<int>& nums){ int l = 0, r = *max_element(nums.begin(), nums.end()); while(l < r) { int mid = l + r >> 1; if(check(nums, mid)) r = mid; else l = mid + 1; } return l; }
boolcheck(vector<int> nums, int limit){ int n = nums.size(); vector<longlong> a(n); a.assign(nums.begin(), nums.end()); for(int i = n - 1; i > 0; i --) { if(a[i] > limit) a[i - 1] += a[i] - limit; } return a[0] <= limit; } };