#include <stdio.h>
int main() {
int data[9] = {1,2,3,4,5,6,7,8,9};
int m = 3;
int low, high, mid;
int result = 0;
low = 9;
high = 45;
while (low <= high) {
mid = (low + high) / 2;
int count = 1;
int sum = 0;
for (int i = 0; i < 9; i++) {
if (sum + data[i] > mid) {
count++;
sum = data[i];
} else {
sum += data[i];
}
}
if (count <= m) {
result = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
printf("%d ", result);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: