#B3732. Turtle's Task Scheduling
Turtle's Task Scheduling
Turtle's Task Scheduling
The turtle has n tasks that have already passed their deadlines. The turtle takes ai units of time to complete the ith task. Starting at time 0, the turtle can choose any task to execute, one after another until all tasks are completed.
Because the deadlines have passed, the turtle will incur a penalty equal to the sum of the completion times of all tasks. For example, if there are 2 tasks which take 10 and 20 units of time respectively, then completing task 1 followed by task 2 will incur a penalty of 10 + (10 + 20) = 40, while doing task 2 first then task 1 incurs a penalty of 20 + (20 + 10) = 50.
Your goal is to determine the order in which the tasks should be executed to minimize the total penalty.
Input Generation: In the test cases, the processing times are generated using a sequence R defined as follows:
\(R_1\) is given in input and satisfies \(0 \le R_1 1\), \[ R_i = (R_{i-1} \times 6807 + 2831) \mod 201701. \]
For the first task, let \(a_1 = R_1\), and for \(i > 1\), let \(a_i = R_i\>.
inputFormat
The first line of input contains two integers n and R1 separated by a space. Here, n (\(1 \le n \le \text{upper limit}\)) is the number of tasks and R1 is the first element of the sequence used to generate the processing times.
The processing time for the tasks is generated as follows:
- a1 = R1
- For \(i > 1\), ai = (ai-1 \times 6807 + 2831) \mod 201701
outputFormat
Output a single integer: the minimum total penalty. The penalty is defined as the sum of the finishing times of each task when processed in an optimal order (i.e., the order that minimizes this sum).
It is optimal to process the tasks in ascending order of their processing times.
sample
2 10
70921