You are given an array of integers start and an integer d, representing n intervals [start[i], start[i] + d].
You are asked to choose n integers where the ith integer must belong to the ith interval. The score of the chosen integers is defined as the minimum absolute difference between any two integers that have been chosen.
Return the maximumpossible score of the chosen integers.
classSolution { boolhelper(vector<int>& A, int d, longlong m){ longlong nxt = A[0] + m; for(int i = 1; i < A.size(); i++) { longlong mi = A[i], ma = mi + d; if(nxt > ma) returnfalse; nxt = max(nxt, mi) + m; } returntrue; } public: intmaxPossibleScore(vector<int>& start, int d){ longlong l = 0, r = INT_MAX, res = 0; sort(begin(start), end(start)); while(l <= r) { longlong m = l + (r - l) / 2; bool ok = helper(start,d,m); if(ok) { l = m + 1; res = m; } else r = m - 1; } return res; } };