eolymp
bolt
Try our new interface for solving problems
Problems

Batch Scheduling

Batch Scheduling

There is a sequence of \textbf{N} jobs to be processed on one machine. The jobs are numbered from \textbf{1} to \textbf{N}, so that the sequence is \textbf{1}, \textbf{2}, …, \textbf{N}. The sequence of jobs must be partitioned into one or more batches, where each batch consists of consecutive jobs in the sequence. The processing starts at time \textbf{0}. The batches are handled one by one starting from the first batch as follows. If a batch \textbf{b} contains jobs with smaller numbers than batch \textbf{c}, then batch \textbf{b} is handled before batch \textbf{c}. The jobs in a batch are processed successively on the machine. Immediately after all the jobs in a batch are processed, the machine outputs the results of all the jobs in that batch. The output time of a job \textbf{j} is the time when the batch containing \textbf{j} finishes. A setup time \textbf{S} is needed to set up the machine for each batch. For each job \textbf{i}, we know its cost factor \textbf{F_i} and the time \textbf{T_i} required to process it. If a batch contains the jobs \textbf{x}, \textbf{x+1}, …, \textbf{x+k}, and starts at time \textbf{t}, then the output time of every job in that batch is \textbf{t + S + (T_x + T_x_\{+1\} + … + T_\{x+k\})}. Note that the machine outputs the results of all jobs in a batch at the same time. If the output time of job \textbf{i} is \textbf{O_i}, its cost is \textbf{O_i}×\textbf{F_i}. For example, assume that there are \textbf{5} jobs, the setup time \textbf{S = 1}, \textbf{(T_1, T_2, T_3, T_4, T_5) = (1, 3, 4, 2, 1)}, and\textbf{ (F_1, F_2, F_3, F_4, F_5) = (3, 2, 3, 3, 4)}. If the jobs are partitioned into three batches \textbf{\{1, 2\}}, \textbf{\{3\}}, \textbf{\{4, 5\}}, then the output times \textbf{(O_1, O_2, O_3, O_4, O_5) = (5, 5, 10, 14, 14)} and the costs of the jobs are \textbf{(15, 10, 30, 42, 56)}, respectively. The total cost for a partitioning is the sum of the costs of all jobs. The total cost for the example partitioning above is \textbf{153}. You are to write a program which, given the batch setup time and a sequence of jobs with their processing times and cost factors, computes the minimum possible total cost. \InputFile Ваша программа должна читать данные со стандартного ввода. Первая строка содержит количество заданий \textbf{N} (\textbf{1 }≤ \textbf{N} ≤ \textbf{10000}). Вторая строка содержит подготовительное время \textbf{S}, которое является целым числом (\textbf{0} ≤ \textbf{S} ≤ \textbf{50}). Следующие \textbf{N} строк содержат информацию о заданиях \textbf{1}, \textbf{2}, …, \textbf{N} в указанном порядке. В каждой из этих строк первым задается целое число \textbf{T_i} (\textbf{1} ≤ \textbf{T_i} ≤ \textbf{100}) - время выполнения задания. За ним следует целое число \textbf{F_i} (\textbf{1} ≤ \textbf{i }≤ \textbf{100}) - стоимостный коэффициент задания. Your program reads from standard input. The first line contains the number of jobs \textbf{N}, \textbf{1} ≤ \textbf{N} ≤ \textbf{10000}. The second line contains the batch setup time \textbf{S} which is an integer, \textbf{0} ≤ \textbf{S} ≤ \textbf{50}. The following \textbf{N} lines contain information about the jobs \textbf{1}, \textbf{2}, …, \textbf{N} in that order as follows. First on each of these lines is an integer \textbf{T_i}, \textbf{1} ≤ \textbf{T_i} ≤ \textbf{100}, the processing time of the job. Following that, there is an integer \textbf{F_i}, \textbf{1} ≤ \textbf{F_i} ≤ \textbf{100}, the cost factor of the job. \OutputFile Your program writes to standard output. The output contains one line, which contains one integer: the minimum possible total cost.
Time limit 0.1 seconds
Memory limit 256 MiB
Input example #1
2
50
100 100
100 100
Output example #1
45000

Example description: For each test case, the total cost for any partitioning does not exceed 2^31 - 1.