class Solution {
public:
double calHourSpent(vector<int>& dist, int speed) {
int n = dist.size() - 1;
double hourSpent = 0;
for(int i = 0; i < n; i++) {
hourSpent += (dist[i] / speed + (dist[i] % speed != 0));
}
return hourSpent + (double) dist[n] / speed;
}
int minSpeedOnTime(vector<int>& dist, double hour) {
if(hour <= dist.size() - 1){
return -1;
}
int l = 1;
int r = 10e7; // two digit decimal after 10e5
int m;
double pivot;
while(l < r) {
m = l + (r - l) / 2;
pivot = calHourSpent(dist, m);
if(pivot == hour){
r = m;
} else if (pivot > hour){
l = m + 1;
} else {
r = m;
}
}
return r;
}
};