Step 1: Set low to max pages (40), high to sum pages (100), mid = (40+100)/2=70
Range: [40 -------- 70 -------- 100]
Check mid=70
Why: We start with the smallest possible max (largest single book) and largest possible max (all books together)
Step 2: Check if allocation possible with max pages 70: allocate books to students without exceeding 70
Students allocation: [10,20,30] sum=60 ≤70 (student 1), [40] sum=40 ≤70 (student 2), total students used=2 ≤4
Why: Since 2 students suffice, 70 is a valid max, try smaller max to minimize
Step 3: Set high = mid - 1 = 69, mid = (40+69)/2=54
Range: [40 -------- 54 -------- 69]
Check mid=54
Why: Try smaller max to see if allocation still possible
Step 4: Check allocation with max pages 54: allocate books
Students allocation: [10,20] sum=30 ≤54 (student 1), [30] sum=30 ≤54 (student 2), [40] sum=40 ≤54 (student 3), total students=3 ≤4
Why: 3 students suffice, try smaller max
Step 5: Set high = mid - 1 = 53, mid = (40+53)/2=46
Range: [40 -------- 46 -------- 53]
Check mid=46
Why: Try smaller max again
Step 6: Check allocation with max pages 46
Students allocation: [10,20] sum=30 ≤46 (student 1), [30] sum=30 ≤46 (student 2), [40] sum=40 ≤46 (student 3), total students=3 ≤4
Why: 3 students suffice, try smaller max
Step 7: Set high = mid - 1 = 45, mid = (40+45)/2=42
Range: [40 -------- 42 -------- 45]
Check mid=42
Step 8: Check allocation with max pages 42
Students allocation: [10,20] sum=30 ≤42 (student 1), [30] sum=30 ≤42 (student 2), [40] sum=40 ≤42 (student 3), total students=3 ≤4
Why: 3 students suffice, try smaller max
Step 9: Set high = mid - 1 = 41, mid = (40+41)/2=40
Range: [40 -------- 40 -------- 41]
Check mid=40
Why: Try smallest max possible
Step 10: Check allocation with max pages 40
Students allocation: [10,20] sum=30 ≤40 (student 1), [30] sum=30 ≤40 (student 2), [40] sum=40 ≤40 (student 3), total students=3 ≤4
Why: 3 students suffice, try smaller max but low=40 so stop
Result: Final answer: 40
Allocation possible with max pages 40 for 4 students