Step 1: Set low to max book pages (400), high to sum of all pages (1000), mid = (400+1000)/2 = 700
low=400, high=1000, mid=700
Why: We start binary search between max single book and total pages
Step 2: Check if allocation possible with max pages = 700
Student1: 100+200+300=600 ≤ 700
Student2: 400 ≤ 700
Students used: 2 ≤ 3
Why: Allocation fits in 2 students, so 700 is a valid max pages
Step 3: Since 700 works, try smaller max pages: high = mid - 1 = 699
low=400, high=699
Why: Try to find smaller max pages to minimize maximum
Step 4: Calculate new mid = (400+699)/2 = 549, check allocation with max pages = 549
Student1: 100+200=300 ≤ 549
Student2: 300 ≤ 549
Student3: 400 ≤ 549
Students used: 3 ≤ 3
Why: Allocation fits exactly in 3 students, so 549 is valid
Step 5: Try smaller max pages: high = 548
low=400, high=548
Why: Try to reduce max pages further
Step 6: Calculate mid = (400+548)/2 = 474, check allocation with max pages = 474
Student1: 100+200=300 ≤ 474
Student2: 300 ≤ 474
Student3: 400 ≤ 474
Students used: 3 ≤ 3
Why: Allocation fits in 3 students, 474 is valid
Step 7: Try smaller max pages: high = 473
low=400, high=473
Why: Try to reduce max pages further
Step 8: Calculate mid = (400+473)/2 = 436, check allocation with max pages = 436
Student1: 100+200=300 ≤ 436
Student2: 300 ≤ 436
Student3: 400 ≤ 436
Students used: 3 ≤ 3
Why: Allocation fits in 3 students, 436 is valid
Step 9: Try smaller max pages: high = 435
low=400, high=435
Why: Try to reduce max pages further
Step 10: Calculate mid = (400+435)/2 = 417, check allocation with max pages = 417
Student1: 100+200=300 ≤ 417
Student2: 300 ≤ 417
Student3: 400 ≤ 417
Students used: 3 ≤ 3
Why: Allocation fits in 3 students, 417 is valid
Step 11: Try smaller max pages: high = 416
low=400, high=416
Why: Try to reduce max pages further
Step 12: Calculate mid = (400+416)/2 = 408, check allocation with max pages = 408
Student1: 100+200=300 ≤ 408
Student2: 300 ≤ 408
Student3: 400 ≤ 408
Students used: 3 ≤ 3
Why: Allocation fits in 3 students, 408 is valid
Step 13: Try smaller max pages: high = 407
low=400, high=407
Why: Try to reduce max pages further
Step 14: Calculate mid = (400+407)/2 = 403, check allocation with max pages = 403
Student1: 100+200=300 ≤ 403
Student2: 300 ≤ 403
Student3: 400 ≤ 403
Students used: 3 ≤ 3
Why: Allocation fits in 3 students, 403 is valid
Step 15: Try smaller max pages: high = 402
low=400, high=402
Why: Try to reduce max pages further
Step 16: Calculate mid = (400+402)/2 = 401, check allocation with max pages = 401
Student1: 100+200=300 ≤ 401
Student2: 300 ≤ 401
Student3: 400 ≤ 401
Students used: 3 ≤ 3
Why: Allocation fits in 3 students, 401 is valid
Step 17: Try smaller max pages: high = 400
low=400, high=400
Why: Try to reduce max pages further
Step 18: Calculate mid = (400+400)/2 = 400, check allocation with max pages = 400
Student1: 100+200=300 ≤ 400
Student2: 300 ≤ 400
Student3: 400 ≤ 400
Students used: 3 ≤ 3
Why: Allocation fits in 3 students, 400 is valid
Step 19: Try smaller max pages: high = 399
low=400, high=399
Why: Now high < low, stop search
Result: Final minimum max pages = 400
Allocation:
Student1: 100 + 200 = 300
Student2: 300
Student3: 400