#P4634. [CTSC2000] 快乐的蜜月
[CTSC2000] 快乐的蜜月
Description
At the end of each year, the hotel manager receives all pre-orders for the honeymoon room for the next year. Each pre-order contains the following necessary information: arrival date, departure date, and customer identity.
Because the hotel has only one honeymoon room and can host at most one newlywed couple at the same time, not all booking requests can be satisfied.
When some booking requests overlap in time, we say that these booking requests conflict.
For those pre-orders that do not conflict with any other booking request, they will certainly be accepted, because this is good for both the hotel and the customers.
For conflicting booking requests, the manager must reject some of them to ensure that the hotel operates in an orderly manner.
Obviously, for booking requests that conflict within the same time period, the manager can accept at most one of them. The manager may also reject all booking requests within the same time period, because this can avoid disputes among customers.
After making the decision, the manager needs to announce the whole plan publicly to show fairness. This is a decision that must be made carefully, because it involves many factors. The first thing the manager considers is of course profit. He definitely hopes to obtain as much income as possible. However, while pursuing economic benefits, the hotel should also consider social benefits. It should not be too profit-driven and must also take customers’ feelings into account. If the manager decides which bookings to accept or reject purely from the perspective of maximizing profit, it will cause dissatisfaction.
The manager has a consultant who studied marketing. The consultant told the manager that a compromise can be made: give up the most profitable plan, and instead adopt the plan with the -th largest profit. Through accurate market analysis, he found the best value of and told it to the manager.
Now please help the manager: from a large number of booking requests, under the principles above, find the plan with the -th largest profit. The manager will decide which booking requests to accept and reject based on this plan.
Of course, there may be several plans with the same profit. In that case, they are considered the same as the -th largest profit plan and are not distinguished. For example, if there are plans with income and plans with income , then all plans with income belong to the largest profit, and all plans with income belong to the second largest. And so on.
Assume that all check-in and check-out registrations are handled at noon.
Input Format
The first line of the input file contains two numbers, and . Here, indicates that we need to choose the plan with the -th largest profit; indicates that customer identities are divided into categories.
The second line contains an integer , indicating the year of the next year.
The third line contains an integer , indicating that there are a total of booking requests.
In the following lines, each line is one booking request in the format: m1/d1 TO m2/d2 id;
Here, and represent the arrival and departure dates respectively. is an integer () used to identify the customer’s identity category.
The last lines each contain an integer (), representing the daily rate for the honeymoon room for customers with identity code .
Example: a couple arrives on June and leaves on June . If their daily rate is yuan/day, then they stay for two days in total and need to pay yuan.
Output Format
The output file contains only one integer , representing the hotel’s total annual revenue under the plan with the -th largest profit. If the plan with the -th largest profit does not exist, output .
2 1
2000
4
1/1 TO 1/2 1
2/1 TO 2/2 1
3/1 TO 3/2 1
3/1 TO 3/3 1
1
3
Hint
Constraints:
,,,
Translated by ChatGPT 5
京公网安备 11011102002149号