You are given a 0-indexed integer array nums and two integers x and y. In one operation, you must choose an index i such that 0 <= i < nums.length and perform the following:
Decrement nums[i] by x.
Decrement values by y at all indices except the ith one.
Return the minimum number of operations to make all the integers innumsless than or equal to zero.
classSolution { longlonghelper(longlong a, longlong x, longlong y, longlong m){ longlong diff = a - y * m; return (diff + x - y - 1) / (x - y); } boolhelper(vector<int>& A, int x, int y, longlong m){ longlong cnt = 0; for(auto a : A) { if(a <= y * m) continue; cnt += helper(a,x,y,m); if(m < cnt) returnfalse; } returntrue; } public: intminOperations(vector<int>& A, int x, int y){ sort(begin(A), end(A)); longlong l = 0, r = INT_MAX, res = r; while(l <= r) { longlong m = l + (r - l) / 2; bool ok = helper(A,x,y,m); if(ok) { res = min(res,m); r = m - 1; } else l = m + 1; } return res; } };