Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 782 |

@arpitsatnalika | 777 |

@tujhekya | 602 |

@prakharxyz | 601 |

@code_it_ | 591 |

@iamronak | 505 |

@imnm | 500 |

@pradeepkumarjad | 488 |

@satyam0460 | 481 |

@Rahul Jadhav 1 | 466 |

@sivanandh03 | 464 |

Complete Leaderboard |

You are given **N** number of books. Every i^{th} book has** A _{i} **number of pages.

You have to allocate books to

Each book will be allocated to exactly one student. Each student has to be allocated at least one book.

**Note: **Return **-1** if a valid assignment is not possible, and **allotment should be in contiguous order (see the explanation for better understanding).**

**Example 1:**

Input:N = 4 A[] = {12,34,67,90} M = 2Output:113Explanation:Allocation can be done in following ways: {12} and {34, 67, 90} Maximum Pages = 191 {12, 34} and {67, 90} Maximum Pages = 157 {12, 34, 67} and {90} Maximum Pages =113 Therefore, the minimum of these cases is 113, which is selected as the output.

**Example 2:**

Input:N = 3 A[] = {15,17,20} M = 2Output:32Explanation:Allocation is done as {15,17} and {20}

**Your Task:**

Complete **findPages() **function that takes a, n, and m as arguments and **returns **the expected answer.

**Expected Time Complexity** : O(NlogN)

**Expected Auxilliary Space** : O(1)

**Constraints:**

1 <= N <= 10^{5}

1 <= A [ i ] <= 10^{6}

1 <= M <= 10^{5}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Allocate minimum number of pages

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.