Step 1: Set low to max book pages (400), high to sum of all pages (1000), start binary search
low=400, high=1000
Why: Minimum max pages can't be less than largest book, max can't be more than total pages
Step 2: Check mid = (400+1000)/2 = 700, try to allocate books with max pages 700
Try allocation with max_pages=700
Why: Test if 700 is a valid max pages limit
Step 3: Allocate books: Student 1 gets 100+200+300=600 (<=700), Student 2 gets 400 (<=700)
Allocation possible with max_pages=700
Why: 700 works, try smaller max to minimize
Step 4: Set high = mid - 1 = 699, binary search continues
low=400, high=699
Why: Try smaller max pages to find minimum
Step 5: Check mid = (400+699)/2 = 549, try allocation with max pages 549
Try allocation with max_pages=549
Why: Test if 549 is valid max pages limit
Step 6: Allocate books: Student 1 gets 100+200=300 (<=549), next book 300 would exceed 549, so Student 2 gets 300+400=700 (>549) not allowed
Allocation not possible with max_pages=549
Why: 549 too small, need bigger max pages
Step 7: Set low = mid + 1 = 550, binary search continues
low=550, high=699
Why: Increase max pages to allow allocation
Step 8: Check mid = (550+699)/2 = 624, try allocation with max pages 624
Try allocation with max_pages=624
Why: Test if 624 is valid max pages limit
Step 9: Allocate books: Student 1 gets 100+200+300=600 (<=624), Student 2 gets 400 (<=624)
Allocation possible with max_pages=624
Why: 624 works, try smaller max
Step 10: Set high = mid - 1 = 623, binary search continues
low=550, high=623
Why: Try smaller max pages
Step 11: Check mid = (550+623)/2 = 586, try allocation with max pages 586
Try allocation with max_pages=586
Why: Test if 586 is valid max pages limit
Step 12: Allocate books: Student 1 gets 100+200=300 (<=586), next book 300 would exceed 586, Student 2 gets 300+400=700 (>586) not allowed
Allocation not possible with max_pages=586
Step 13: Set low = mid + 1 = 587, binary search continues
low=587, high=623
Step 14: Check mid = (587+623)/2 = 605, try allocation with max pages 605
Try allocation with max_pages=605
Why: Test if 605 is valid max pages limit
Step 15: Allocate books: Student 1 gets 100+200+300=600 (<=605), Student 2 gets 400 (<=605)
Allocation possible with max_pages=605
Why: 605 works, try smaller max
Step 16: Set high = mid - 1 = 604, binary search continues
low=587, high=604
Why: Try smaller max pages
Step 17: Check mid = (587+604)/2 = 595, try allocation with max pages 595
Try allocation with max_pages=595
Why: Test if 595 is valid max pages limit
Step 18: Allocate books: Student 1 gets 100+200=300 (<=595), next book 300 would exceed 595, Student 2 gets 300+400=700 (>595) not allowed
Allocation not possible with max_pages=595
Step 19: Set low = mid + 1 = 596, binary search continues
low=596, high=604
Step 20: Check mid = (596+604)/2 = 600, try allocation with max pages 600
Try allocation with max_pages=600
Why: Test if 600 is valid max pages limit
Step 21: Allocate books: Student 1 gets 100+200+300=600 (<=600), Student 2 gets 400 (<=600)
Allocation possible with max_pages=600
Why: 600 works, try smaller max
Step 22: Set high = mid - 1 = 599, binary search continues
low=596, high=599
Why: Try smaller max pages
Step 23: Check mid = (596+599)/2 = 597, try allocation with max pages 597
Try allocation with max_pages=597
Why: Test if 597 is valid max pages limit
Step 24: Allocate books: Student 1 gets 100+200=300 (<=597), next book 300 would exceed 597, Student 2 gets 300+400=700 (>597) not allowed
Allocation not possible with max_pages=597
Step 25: Set low = mid + 1 = 598, binary search continues
low=598, high=599
Step 26: Check mid = (598+599)/2 = 598, try allocation with max pages 598
Try allocation with max_pages=598
Why: Test if 598 is valid max pages limit
Step 27: Allocate books: Student 1 gets 100+200=300 (<=598), next book 300 would exceed 598, Student 2 gets 300+400=700 (>598) not allowed
Allocation not possible with max_pages=598
Step 28: Set low = mid + 1 = 599, binary search continues
low=599, high=599
Step 29: Check mid = (599+599)/2 = 599, try allocation with max pages 599
Try allocation with max_pages=599
Why: Test if 599 is valid max pages limit
Step 30: Allocate books: Student 1 gets 100+200=300 (<=599), next book 300 would exceed 599, Student 2 gets 300+400=700 (>599) not allowed
Allocation not possible with max_pages=599
Step 31: Set low = mid + 1 = 600, now low > high, binary search ends
low=600, high=599
Why: Search space exhausted, minimum max pages found
Result: Final allocation max pages = 600
Books allocation:
Student 1: 100 -> 200 -> 300 -> null
Student 2: 400 -> null