Improving Grades
InterviewTime limit1sMemory limit512 MB
Given counts of scores 2, 3, and 4, find the minimum number of 5s to add so the rounded mean reaches at least 4.
- Level
Medium4 of 10
- Topics
- Binary search, Math, Greedy, Brute force
- Solved
- No attempts yet
Problem
In the informatics classes at a lyceum, students' answers are graded with an integer score from 2 to 5. The final grade in informatics is the arithmetic mean of the scores from all classes, rounded to the nearest integer. If the mean falls exactly halfway between two integers, the grade is rounded up.
Examples of grade rounding are given in the table.
Every student at the lyceum wants a final grade in informatics of at least 4. Unfortunately, one student received a twos, b threes, and c fours in class. Now he plans to earn several fives, and he wants the final grade to be at least 4. He needs to figure out the minimum number of fives he must earn to reach his goal.
Write a program that, given non-negative integers a, b, and c, determines the minimum number of fives the student must earn for his final grade in informatics to be at least 4.
Input
The input consists of three lines. The first line contains a non-negative integer a, the second line contains a non-negative integer b, and the third line contains a non-negative integer c (0 ≤ a, b, c ≤ 1015, a + b + c ≥ 1).
Output
Print one number: the minimum number of fives the student must earn for the final grade to be at least 4.