-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fest and pesters
46 lines (43 loc) · 1.11 KB
/
Fest and pesters
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class Solution {
public:
bool ispossible(vector<int> &time , int NUM , int N , long long int v)
{
long long int c = 0 ;
for(int i = 0 ; i < time.size() ; i++)
{
c = c + (v /(long long int)time[i] ) ;
}
if(c >= NUM)
{
return true ;
}
return false ;
}
long long minimumTime(int N, int NUM, vector<int> &time) {
// code here
int m = 1e9 ;
for(int i = 0 ; i < time.size() ; i++)
{
m = min(m , time[i]) ;
}
long long int l = 1 ;
long long int r = m* (long long int)NUM ;
long long int res = r ;
while( l <= r)
{
long long int mid= l + (r - l)/2 ;
bool a = ispossible(time , NUM , N , mid) ;
if(a == false )
{
l = mid + 1 ;
}
else
{
// cout << mid << " ";
r = mid - 1;
res = min(res , mid) ;
}
}
return res;;
}
};