Food Portion Size
Time limit1sMemory limit128 MB
Choose a real portion size S to minimize a*(wasted food) + b*(number of servings, each student at most 3), and print the optimum as a reduced fraction.
- Level
Medium7 of 10
- Topics
- Math, Brute force, Implementation, Greedy
- Solved
- No attempts yet
Problem
A university canteen never wants a student to leave hungry, so as long as a student is still hungry they may take another portion of food for free. To avoid wasting time, the canteen always serves one fixed portion size instead of first asking each student how much they want. Because of this, a student might not finish their final portion, and whatever is left over must be thrown away.
To keep costs down, the manager wants to choose a portion size so that little food is wasted while students also do not have to come back for more food too often. The two goals conflict:
- A very small wastes almost no food, but students must refill many times.
- A very large lets each student take just one portion, but a large amount of food may be wasted.
The manager has recorded how many units of food each student eats. Let be the total food wasted and let be the total number of times students go to fetch food. The goal is to minimize , where the weights and express the relative importance of the two goals. Both and depend on the portion size (which may be any positive real value) and on how much each student eats. One extra rule applies: no student may fetch food more than times.
Input
The input contains several test cases. Each test case begins with a line containing an integer (), the number of students. The next line contains two integers and (). The third line contains integers (), where is the number of food units that student eats. The input ends with a line containing , which should not be processed.
Output
For each test case, print one line with the minimum possible value of over all valid portion sizes. Print the value as a reduced fraction in the form p / q. If the value is an integer, print only the numerator and omit the denominator .