Step 1: Set low to max book pages (400), high to sum of all pages (1000), mid = (400+1000)/2 = 700
low=400, mid=700, high=1000
Why: We start binary search between max single book and total pages
Step 2: Check if max pages 700 can allocate books to 3 students
Student1: 100 + 200 + 300 = 600 ≤ 700
Student2: 400 ≤ 700
Students used: 2 ≤ 3
Why: 700 is a valid max pages since only 2 students needed
Step 3: Since 700 works, try smaller max by setting high = mid = 700
low=400, high=700
Why: Try to find smaller max pages to minimize maximum
Step 4: Calculate new mid = (400+700)/2 = 550
low=400, mid=550, high=700
Why: Check feasibility with smaller max pages
Step 5: Check if max pages 550 can allocate books
Student1: 100 + 200 = 300 ≤ 550
Student2: 300 ≤ 550
Student3: 400 ≤ 550
Students used: 3 ≤ 3
Why: 550 is valid max pages with exactly 3 students
Step 6: Since 550 works, set high = mid = 550
low=400, high=550
Why: Try smaller max pages again
Step 7: Calculate new mid = (400+550)/2 = 475
low=400, mid=475, high=550
Why: Check feasibility with 475 max pages
Step 8: Check if max pages 475 can allocate books
Student1: 100 + 200 = 300 ≤ 475
Student2: 300 ≤ 475
Student3: 400 > 475 (needs new student)
Students used: 4 > 3 (not valid)
Why: 475 is too small, need more than 3 students
Step 9: Since 475 not valid, set low = mid + 1 = 476
low=476, high=550
Why: Increase minimum max pages
Step 10: Calculate new mid = (476+550)/2 = 513
low=476, mid=513, high=550
Why: Check feasibility with 513 max pages
Step 11: Check if max pages 513 can allocate books
Student1: 100 + 200 = 300 ≤ 513
Student2: 300 ≤ 513
Student3: 400 ≤ 513
Students used: 3 ≤ 3 (valid)
Why: 513 works with 3 students
Step 12: Since 513 works, set high = mid = 513
low=476, high=513
Why: Try smaller max pages
Step 13: Calculate new mid = (476+513)/2 = 494
low=476, mid=494, high=513
Why: Check feasibility with 494 max pages
Step 14: Check if max pages 494 can allocate books
Student1: 100 + 200 = 300 ≤ 494
Student2: 300 ≤ 494
Student3: 400 > 494 (needs new student)
Students used: 4 > 3 (not valid)
Why: 494 too small, need more students
Step 15: Since 494 not valid, set low = mid + 1 = 495
low=495, high=513
Why: Increase minimum max pages
Step 16: Calculate new mid = (495+513)/2 = 504
low=495, mid=504, high=513
Why: Check feasibility with 504 max pages
Step 17: Check if max pages 504 can allocate books
Student1: 100 + 200 = 300 ≤ 504
Student2: 300 ≤ 504
Student3: 400 ≤ 504
Students used: 3 ≤ 3 (valid)
Why: 504 works with 3 students
Step 18: Since 504 works, set high = mid = 504
low=495, high=504
Why: Try smaller max pages
Step 19: Calculate new mid = (495+504)/2 = 499
low=495, mid=499, high=504
Why: Check feasibility with 499 max pages
Step 20: Check if max pages 499 can allocate books
Student1: 100 + 200 = 300 ≤ 499
Student2: 300 ≤ 499
Student3: 400 > 499 (needs new student)
Students used: 4 > 3 (not valid)
Step 21: Since 499 not valid, set low = mid + 1 = 500
low=500, high=504
Why: Increase minimum max pages
Step 22: Calculate new mid = (500+504)/2 = 502
low=500, mid=502, high=504
Why: Check feasibility with 502 max pages
Step 23: Check if max pages 502 can allocate books
Student1: 100 + 200 = 300 ≤ 502
Student2: 300 ≤ 502
Student3: 400 ≤ 502
Students used: 3 ≤ 3 (valid)
Step 24: Since 502 works, set high = mid = 502
low=500, high=502
Why: Try smaller max pages
Step 25: Calculate new mid = (500+502)/2 = 501
low=500, mid=501, high=502
Why: Check feasibility with 501 max pages
Step 26: Check if max pages 501 can allocate books
Student1: 100 + 200 = 300 ≤ 501
Student2: 300 ≤ 501
Student3: 400 > 501 (needs new student)
Students used: 4 > 3 (not valid)
Step 27: Since 501 not valid, set low = mid + 1 = 502
low=502, high=502
Why: low meets high, search ends
Result: Final minimum max pages = 502
Books distributed as:
Student1: 100 + 200 = 300
Student2: 300
Student3: 400