leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1870.cpp (583B)


      1 class Solution {
      2   public:
      3     int minSpeedOnTime(vector<int> &dist, double hour) {
      4         int low = 1, high = 10000000;
      5         int res = -1;
      6         while (low <= high) {
      7             int mid = low + (high - low) / 2;
      8             double time = 0;
      9             for (int i = 0; i < dist.size() - 1; i++)
     10                 time += ceil((double)dist[i] / mid);
     11             time += (double)dist.back() / mid;
     12             if (time <= hour) {
     13                 res = mid;
     14                 high = mid - 1;
     15             } else
     16                 low = mid + 1;
     17         }
     18         return res;
     19     }
     20 };