COI '20 #1 Autobahn

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem type

There are N people testing their racing cars on notorious autobahn where limits do not exist. In this task however limits do exist. So we kindly ask you to restrain yourself from submitting exponential complexity solutions.

Person i came to autobahn at the beginning of minute li, paid for ti minutes of stay and left at the end of minute ri. Unfortunately some stayed for longer than what they have paid for. Administration of autobahn decided not to be very harsh and charge them only for those extra minutes in which there were at least K people on autobahn.

In a rush of generosity, administration decided to introduce happy hour i.e. interval of continuous X minutes for which they won't be paying extra charges. They picked happy hour so that the sum of extra charges that won't be paid is maximal possible. Determine that sum.

Input Specification

First line contains integers N, K and X (KN) from task description.

Next N lines contain integers li, ti and ri (liri) from task description.

Output Specification

Print the required sum in a single line.

Scoring

Subtask Points Constraints
1 20 1N,K,X,li,ti,ri100
2 30 1N,K,X,li,ti,ri1000
3 50 1N105, 1X,li,ti,ri109

Sample Input 1

Copy
5 3 4
2 1 4
3 3 7
3 3 8
1 5 7
5 3 8

Sample Output 1

Copy
7

Explanation for Sample Output 1

Happy hour will span from 4th until the 7th minute. Inside that interval, first person should've paid extra for the 4th minute and second, third and fourth person should've paid for 6th and 7th minute.

Sample Input 2

Copy
3 2 22
7 16 33
69 14 88
8 10 97

Sample Output 2

Copy
27

Comments

There are no comments at the moment.