Skip to content

Commit

Permalink
Time: 554 ms (24.58%), Space: 94.4 MB (76.55%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipendra-Raghav committed Mar 7, 2023
1 parent d2985d8 commit 780ece6
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Solution {
public:

bool isValid(long long mid,vector<int> &time, int k)
{
long long cnt = 0;
for(int i : time) {
cnt += mid / i;
if(cnt >= 1e18) return true;
}
return cnt >= k;

}
long long minimumTime(vector<int>& time, int totalTrips) {
long long s=1;
long long e = 1e18;
long long ans=0;
while(s<=e)
{
long long mid=(s+e)/2;
if(isValid(mid,time,totalTrips))
{
e=mid-1;
ans=mid;
}
else
{
s=mid+1;
}
}

return ans;

}
};

0 comments on commit 780ece6

Please sign in to comment.