Allocate Minimum Pages using Binary Search on Answer
📖 Scenario: You are a librarian who needs to allocate books to students. Each book has a certain number of pages. You want to distribute the books so that the student who gets the most pages has as few pages as possible. Books must be allocated in order and each student must get at least one book.
🎯 Goal: Build a program that finds the minimum possible maximum number of pages assigned to a student using binary search on the answer.
📋 What You'll Learn
Create a vector called
books with these exact page counts: 12, 34, 67, 90Create an integer variable called
students and set it to 2Write a function called
isPossible that takes books, students, and a maxPages integer, and returns true if allocation is possible without exceeding maxPages per studentUse binary search between the maximum single book pages and the sum of all pages to find the minimum maximum pages
Print the minimum maximum pages after allocation
💡 Why This Matters
🌍 Real World
This problem models distributing workloads or resources evenly, such as assigning books to students or tasks to workers.
💼 Career
Understanding binary search on answer is useful in software engineering roles that require optimization and efficient resource allocation.
Progress0 / 4 steps