Course Registration
Time limit2sMemory limit256 MB
Choose courses so total credits fall between n_lo and n_hi, maximizing the sum of their happiness scores, with each course credit at most 5.
- Level
Medium6 of 10
- Topics
- Greedy, Sorting, Dynamic programming
- Solved
- No attempts yet
Problem
This semester, GIST offers courses in total. Cheongeung wants to take at least credits and at most credits. After looking through the course list, Cheongeung gave every course a happiness score. The happiness for the semester is the sum of the happiness scores of all courses taken. Timetable conflicts do not need to be considered. Write a program that finds the maximum happiness Cheongeung can get this semester.
Input
The first line contains and , the minimum and maximum credits, separated by a space. They satisfy .
The second line contains , the number of courses offered this semester. It satisfies .
Each of the next lines contains the credit and the happiness of course , separated by a space. They satisfy and . The input always contains at least one combination of courses that meets the credit requirement.
Output
Print the maximum happiness Cheongeung can get this semester.