2366.cpp (390B)
1 class Solution { 2 public: 3 long long minimumReplacement(vector<int> &nums) { 4 long long int res = 0; 5 for (int i = nums.size() - 2; i >= 0; i--) { 6 if (nums[i] <= nums[i + 1]) continue; 7 long long num = (nums[i] + nums[i + 1] - 1) / nums[i + 1]; 8 res += num - 1; 9 nums[i] = nums[i] / num; 10 } 11 return res; 12 } 13 };