3
// function to check if it is possible to ship all the items within the given4
// number of days using a given weight capacity5
bool isPossible(int cp, vector<int> &weights, int days) {8
// iterate through the weights and check if it is possible to ship all the10
for (auto x : weights) {12
// if the current weight can be added to the current capacity, add it15
// if not, increment the number of days required for shipping and start20
// if the current weight is greater than the current capacity, it is21
// impossible to ship all the items26
// check if it is possible to ship all the items within the given number of31
// function to find the minimum weight capacity required to ship all the items32
// within the given number of days33
int shipWithinDays(vector<int> &weights, int days) {34
// initialize the search range for the weight capacity39
// perform binary search on the weight capacity range41
// set the mid-point of the range as the current weight capacity42
int mid = (s + e) / 2;44
// check if it is possible to ship all the items within the given number45
// of days using the current weight capacity46
bool ok = isPossible(mid, weights, days);48
// if it is possible to ship all the items within the given number of days49
// using the current weight capacity, set the current weight capacity as50
// the new answer and reduce the upper bound of the weight capacity range55
// if it is not possible to ship all the items within the given number56
// of days using the current weight capacity, increase the lower bound57
// of the weight capacity range62
// return the minimum weight capacity required to ship all the items within63
// the given number of days