-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbookAllocation.cpp
More file actions
49 lines (43 loc) · 885 Bytes
/
bookAllocation.cpp
File metadata and controls
49 lines (43 loc) · 885 Bytes
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
47
48
49
#include <iostream>
using namespace std;
bool isPossibleSol(int n,int m, int arr[],int mid){
int dayCount = 1;
int timeSum = 0;
for(int i = 0;i<m;i++){
if(timeSum + arr[i] <= mid){
timeSum += arr[i];
}
else{
dayCount++;
if(dayCount > n || arr[i] > mid){
return false;
}
timeSum = arr[i];
}
}
return true;
}
long long ayushGivesNinjatest(int n, int m, int time[])
{
int s = 0;
int sum=0;
for(int i = 0; i<m;i++){
sum += time[i];
}
int e = sum;
int ans=-1;
int mid = s + (e-s)/2;
while(s <= e){
if (isPossibleSol(n,m,time,mid)){
ans = mid;
e = mid-1;
}
else{
s = mid + 1;
}
mid = s + (e-s)/2;
}
return ans;
}
int main(){
}