classSolution { public: boolcheck(vector<int>& dist, double& hour, int index){ double time = 0; for (int i = 0; i < dist.size() - 1; i++) { time += ceil((double)dist[i] / index); } time += (double)dist.back() / index;
return time <= hour; } intminSpeedOnTime(vector<int>& dist, double hour){ if (dist.size() > ceil(hour)) { return-1; }
int left = 1; int right = INT_MAX; while (left < right) { int mid = left + ((right - left) >> 1); if (check(dist, hour, mid)) { right = mid; } else { left = mid + 1; } }
int left = 1; int right = INT_MAX; auto check = [&](int index)->bool { double time = 0; for (int i = 0; i < dist.size() - 1; i++) { time += ceil((double)dist[i] / index); } time += (double)dist.back() / index;
return time <= hour; }; while (left < right) { int mid = left + ((right - left) >> 1); if (check(mid)) { right = mid; } else { left = mid + 1; } }