Brazilian Popcorn Marathon
InterviewTime limit1.5sMemory limit512 MB
Split a row of popcorn bags into at most C contiguous segments, minimizing the maximum segment sum given each competitor eats at most T per second.
- Level
Medium5 of 10
- Topics
- Binary search, Greedy, Array, Prefix sum
- Solved
- No attempts yet
Problem
The Maratona Brasileira de Popcorn is a competition held every year to find out which team is the most organized, the best prepared, and the best trained in the art of eating popcorn. It is organized by the Brazilian Society of Popcorn Eaters (SBCp), which meets regularly to discuss the rules and format of the competition.
The competition consists of N popcorn bags placed side by side, each with an arbitrary amount of popcorn. To make it more fun, the competition is held in teams, each made up of C competitors. Since the Maratona Brasileira de Popcorn is a serious event that values the health of the competitors above all, the medical commission has ruled that each competitor may eat at most T popcorn per second to avoid possible illness.
At its last meeting, SBCp set two new rules for the 2019 edition:
- Each team competitor must eat a contiguous sequence of popcorn bags. It is perfectly valid for a competitor to eat no popcorn at all.
- All popcorn in the same bag must be eaten by a single competitor.
The goal of the competition is to eat all the popcorn in the shortest possible time, given that the C competitors can eat in parallel and will follow all the rules set by SBCp.
Input
The first line of input contains three integers N, C, T (1 ≤ N ≤ 10^5, 1 ≤ C ≤ 10^5, 1 ≤ T ≤ 50), representing the number of popcorn bags in the competition, the number of competitors on the team, and the maximum amount of popcorn per second a competitor can eat. The second line contains N integers P_i (1 ≤ P_i ≤ 10^4), representing the amount of popcorn in each of the N popcorn bags.
Output
Your program must output a single line containing one integer, the minimum number of seconds it takes for the team to eat all the popcorn if they organize themselves as well as possible.