Step 1: Set low to max book pages (500), high to sum of all pages (1500), mid = (500+1500)//2 = 1000
low=500, mid=1000, high=1500
Why: We start binary search between max single book and total pages
Step 2: Check if we can allocate books with max pages per student = 1000
Allocation: Student1: 100+200+300=600 ≤1000, Student2: 400 ≤1000, Student3: 500 ≤1000
Why: 1000 is enough to allocate all books to 3 students
Step 3: Since allocation possible, try smaller max: high = mid - 1 = 999
low=500, high=999
Why: Try to find smaller max pages to minimize maximum
Step 4: Calculate new mid = (500+999)//2 = 749
low=500, mid=749, high=999
Why: Check feasibility with smaller max pages
Step 5: Check allocation with max pages = 749
Student1: 100+200+300=600 ≤749, Student2: 400 ≤749, Student3: 500 ≤749
Why: Allocation still possible with 749 max pages
Step 6: Try smaller max again: high = mid - 1 = 748
low=500, high=748
Why: Try to minimize max pages further
Step 7: Calculate mid = (500+748)//2 = 624
low=500, mid=624, high=748
Why: Check feasibility with 624 max pages
Step 8: Check allocation with max pages = 624
Student1: 100+200+300=600 ≤624, Student2: 400 ≤624, Student3: 500 ≤624
Why: Allocation possible with 624 max pages
Step 9: Try smaller max: high = mid - 1 = 623
low=500, high=623
Why: Try to minimize max pages further
Step 10: Calculate mid = (500+623)//2 = 561
low=500, mid=561, high=623
Why: Check feasibility with 561 max pages
Step 11: Check allocation with max pages = 561
Student1: 100+200=300 ≤561, Student2: 300+400=700 >561 (not allowed), allocation fails
Why: Cannot allocate all books within 561 max pages
Step 12: Increase low: low = mid + 1 = 562
low=562, high=623
Why: Try larger max pages since 561 failed
Step 13: Calculate mid = (562+623)//2 = 592
low=562, mid=592, high=623
Why: Check feasibility with 592 max pages
Step 14: Check allocation with max pages = 592
Student1: 100+200=300 ≤592, Student2: 300+400=700 >592 (fail)
Why: Allocation fails again with 592 max pages
Step 15: Increase low: low = mid + 1 = 593
low=593, high=623
Why: Try larger max pages
Step 16: Calculate mid = (593+623)//2 = 608
low=593, mid=608, high=623
Why: Check feasibility with 608 max pages
Step 17: Check allocation with max pages = 608
Student1: 100+200=300 ≤608, Student2: 300+400=700 >608 (fail)
Why: Allocation fails again
Step 18: Increase low: low = mid + 1 = 609
low=609, high=623
Why: Try larger max pages
Step 19: Calculate mid = (609+623)//2 = 616
low=609, mid=616, high=623
Why: Check feasibility with 616 max pages
Step 20: Check allocation with max pages = 616
Student1: 100+200=300 ≤616, Student2: 300+400=700 >616 (fail)
Why: Allocation fails again
Step 21: Increase low: low = mid + 1 = 617
low=617, high=623
Why: Try larger max pages
Step 22: Calculate mid = (617+623)//2 = 620
low=617, mid=620, high=623
Why: Check feasibility with 620 max pages
Step 23: Check allocation with max pages = 620
Student1: 100+200=300 ≤620, Student2: 300+400=700 >620 (fail)
Why: Allocation fails again
Step 24: Increase low: low = mid + 1 = 621
low=621, high=623
Why: Try larger max pages
Step 25: Calculate mid = (621+623)//2 = 622
low=621, mid=622, high=623
Why: Check feasibility with 622 max pages
Step 26: Check allocation with max pages = 622
Student1: 100+200=300 ≤622, Student2: 300+400=700 >622 (fail)
Why: Allocation fails again
Step 27: Increase low: low = mid + 1 = 623
low=623, high=623
Why: Try larger max pages
Step 28: Check allocation with max pages = 623
Student1: 100+200+300=600 ≤623, Student2: 400 ≤623, Student3: 500 ≤623
Why: Allocation possible at 623 max pages
Step 29: Since low == high, binary search ends with answer = 623
low=623, high=623
Why: Found minimum max pages for allocation
Result: Final allocation max pages = 623
Books allocation example:
Student1: 100 -> 200 -> 300 -> null
Student2: 400 -> null
Student3: 500 -> null