#P5585. 「SWTR-1」Doing Homework
「SWTR-1」Doing Homework
Background
Little has a lot of homework to do every day.
Problem Description
Every day, Little must do at least tons of homework. If he fails to reach the goal, he will be punished by Little and die on the spot.
Little has energy points. Each time he does homework, Little ’s energy decreases, and this is irreversible. Little ’s energy cannot drop below .
Now, there are types of homework for Little to choose from.
Each type of homework has the following attributes:
: energy cost, i.e., doing one copy of this type of homework requires energy.
: weight, i.e., one copy of this type of homework weighs tons.
: deadline, i.e., after days from today, this homework can no longer be done.
There are infinitely many copies of each type of homework.
Since he has too much homework to ever finish, please arrange a homework plan for him to maximize the number of days he can survive. When the number of surviving days is maximized, maximize his remaining energy.
Input Format
The first line contains two positive integers , representing Little ’s energy and the daily goal.
The next line contains one positive integer , indicating the number of types of homework.
The next lines each contain three integers .
Output Format
Output two numbers separated by a space, representing the maximum number of days Little can survive, and his remaining energy.
30 4
3
5 3 8
3 2 2
8 4 4
4 2
100 3
2
3 2 8
2 1 5
8 57
Hint
Sample Explanation
On day , Little chooses to do copies of the second type of homework. The weight is , and the remaining energy is .
On day , Little chooses to do copies of the second type of homework. The weight is , and the remaining energy is .
At this point, he can no longer do the second type of homework .
On day , Little chooses to do copy of the third type of homework. The weight is , and the remaining energy is .
On day , Little chooses to do copy of the third type of homework. The weight is , and the remaining energy is .
At this point, he can no longer do the third type of homework .
Little has no energy left to do any other homework, so he can survive at most days, with energy remaining.
It can be proven that no better plan than this one can be found.
Constraints

For of the testdata with , the time limit is and the memory limit is .
For the remaining test points, the time limit is and the memory limit is .
Translated by ChatGPT 5