Batch Scheduling
Time limit1sMemory limit128 MB
Split the ordered jobs into consecutive batches, each paying a setup time, and minimize the sum of weighted completion times.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Prefix sum, Greedy
- Solved
- No attempts yet
Problem
A single machine processes jobs numbered through in order. The job sequence must be split into one or more batches, where each batch is a group of consecutive jobs.
Processing starts at time . The batches are handled one at a time starting from the first, and a batch containing lower-numbered jobs is handled before one containing higher-numbered jobs. Before each batch, the machine needs a setup time .
If a batch consists of jobs and starts at time , then the output (completion) time of every job in that batch is The machine outputs all results of a batch at the same time, and the next batch starts immediately afterward.
Each job has a processing time and a cost factor . If the output time of job is , its cost is . The total cost of a partition is the sum of the costs of all jobs.
Given the setup time together with each job's processing time and cost factor, write a program that computes the minimum possible total cost.
Input
The first line contains the number of jobs ().
The second line contains the setup time as an integer ().
Each of the next lines describes jobs in order. Each line contains two integers and , where is the processing time of the job () and is its cost factor ().
Output
Print the minimum possible total cost as a single integer on one line.
Note
For every test case, the total cost of any partition does not exceed .