#P1833. 樱花

樱花

Description

Ai Yu Chou has planted nn cherry blossom trees in the backyard, each with an aesthetic value CiC_i (0<Ci2000 < C_i \le 200). Every morning before school, Ai Yu Chou enjoys the blossoms. As a biology ace, he knows how to appreciate them: each tree can be viewed at most PiP_i times, where Pi=0P_i = 0 means unlimited views; otherwise, at most PiP_i times. Viewing tree ii once takes TiT_i minutes (0<Ti1000 < T_i \le 100). Only a short time remains before he must leave for school. Determine which trees to view (and how many times) to maximize the total aesthetic value while ensuring he can leave on time (or earlier).

Input Format

There are n+1n+1 lines.

Line 1: current time TsT_s (hour:minute), school departure time TeT_e (hour:minute), and the number of trees nn. The formats of TsT_s, TeT_e are hh:mm, where 0hh230 \le hh \le 23, 0mm590 \le mm \le 59, and nn is a positive integer.

Lines 22 to n+1n+1: three positive integers per line: the time to view tree ii once TiT_i, the aesthetic value of tree ii CiC_i, and the allowed view count PiP_i (Pi=0P_i = 0 means unlimited; otherwise, at most PiP_i times).

Output Format

Output a single integer, the maximum total aesthetic value.

6:50 7:00 3
2 1 0
3 3 1
4 5 4
11

Hint

Constraints: For 100%100\% of the testdata, TeTs1000T_e - T_s \le 1000 (i.e., the time from start to end does not exceed 10001000 minutes), and n10000n \le 10000. It is guaranteed that TeT_e and TsT_s are within the same day.

Sample explanation: view the first tree once, and the third tree 22 times.

Translated by ChatGPT 5