Doing Assignments Efficiently
InterviewTime limit1sMemory limit1024 MB
Pick a subset of assignments to do shortest-first, maximizing points (half for late work within 24 hours), then report the least total time that achieves that maximum.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Sorting
- Solved
- No attempts yet
Problem
Kim Hanyang is exhausted from the backlog of assignments, even during exam period. He already did badly on the midterm, and he does not want to retake the course, so he wants to finish the assignments quickly and study for the final exam.
To avoid a retake, more points from assignments are better. Studying for the final takes a lot of time, so less time spent on assignments is also better. Kim Hanyang cares more about the total points of the assignments than the total time they take. So, when he gets the most points, doing the assignments in order of shortest time is the most efficient plan for him. If he can get the most points, he is fine with skipping some assignments.
To make this plan, Kim Hanyang lined up all the assignments in a row. For each -th assignment , he recorded in a table the time (hours) needed to finish it, the time (hours) left from now until the deadline, and the points .
If he starts assignment now, he gets the following points.
- If he finishes within hours, he gets the full points.
- If he finishes after but within hours, it is a late submission, so he gets points.
- If he finishes after hours, he gets 0 points.
He is focused enough that each assignment takes exactly hours, but not focused enough to work on two assignments at once.
Input
The first line contains the number of assignments (). The next lines each contain three positive integers: the time (), the time left (), and the points () for the -th assignment. All values are separated by spaces.
Output
Print the maximum points Kim Hanyang can get by following the efficient plan, and the minimum time (hours) it takes to get those points, separated by a space.