A Lazy Worker
Time limit1sMemory limit128 MB
Jobs have processing times with arrival times and deadlines, and the worker picks among available jobs without idling to minimize total executed work.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Sorting
- Solved
- No attempts yet
Problem
There is a lazy worker who wants to do as little work as possible. He is under one constraint: whenever there is a job he is able to work on, he must be busy working.
There are jobs , and job has processing time . Job arrives at time and has deadline , where , , and are nonnegative integers. Every job has a hard deadline: job may only be executed inside its allowed interval , so it must start no earlier than and finish no later than .
The worker handles only one job at a time, and once a job is started it runs to completion without interruption. When a job finishes, the worker must immediately begin another job if one is available. If no job is available, the worker stays idle and starts a job as soon as one becomes available.
For every job the interval length is at least and strictly less than .
The worker may choose which of the available jobs to run next, and different choices may cause some jobs to miss their deadlines and never be executed. Write a program that finds the minimum possible total time the worker spends working, that is, the minimum possible sum of processing times over the jobs he actually executes.
Input
The input consists of test cases. The first line contains the number of test cases .
The first line of each test case contains the number of jobs (). Each of the next lines contains three integers: the processing time , the arrival time , and the deadline of one job. The values satisfy , , , and each job satisfies .
Output
For each test case, print exactly one line containing the minimum total amount of time the worker spends working.