Make America Grade Again
InterviewTime limit1sMemory limit512 MB
Given category weights and a list of graded assignments, sum points per category, weight each fraction, and print the truncated final grade.
- Level
Medium4 of 10
- Topics
- Math, Implementation, String, Simulation
- Solved
- No attempts yet
Problem
The University of America has an integrity problem. It turns out that grades in many science classes are based not on graded work but on attendance, grooming habits, and whatever snacks the students bring. The administration decided to crack down. First it confiscated all the snacks. Then it insisted that every grade in a science class must come from graded work in four categories: labs, homeworks, projects, and exams. It does not care what percentage of the final grade each category gets, as long as the percentages total 100%.
The professors at UA grudgingly agreed to start grading their assignments, but they balk at calculating final grades. They want you to write a program that computes a student's final grade. They will give you the following information: first, the percentage of each of the four categories; second, a list of (grudgingly) graded assignments, each belonging to one category. From this, compute a final integer percentage grade.
For example, suppose the assigned percentages are labs 20, homeworks 20, projects 25, and exams 35, and the list of graded assignments is:
- Lab 1: 15/20
- Hw 1: 65/70
- Hw 2: 27/35
- Exam 1: 88/100
- Proj 1: 50/50
- Hw 3: 61/65
- Exam 2: 79/100
- Lab 2: 17/20
- Hw 4: 51/60
- Exam 3: 141/150
To compute the final grade, first total the fraction of points earned in each category. For labs it is 32/40 (there were two assignments worth 20 each, and the student got 15 on the first and 17 on the second, for 32 points). For homeworks it is 204/230, for projects 50/50, and for exams 308/350. Then multiply each fraction by the percentage assigned to its category: 20(32/40) + 20(204/230) + 25(50/50) + 35(308/350) = 89.539. Finally truncate to get the final grade 89. Then sit back and eat all the snacks you no longer need to bring to class.
Input
Input starts with five positive integers l h p e n. The first four are the percentages for labs, homeworks, projects, and exams respectively (they always total 100), and n (4 ≤ n ≤ 200) is the number of graded assignments. The next n lines each have the form cat i: r/s, where cat is Lab, Hw, Proj, or Exam, i is a positive integer, r is the number of points earned on the assignment, and s is the total possible points. On each of these lines s is positive and 0 ≤ r ≤ s ≤ 1 000. Each of the four categories always contains at least one assignment.
Output
Output the final truncated percentage grade.