Employees
Time limit2sMemory limit512 MB
Given n employees with distinct workloads and hall size k, output for each employee the product of two permutation-based scores, modulo 1e9+7.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Combinatorics, Sorting, Math
- Solved
- No attempts yet
Problem
There are employees in the company Yooglex. The -th employee has to work time units per day. These values are different for all employees. Yooglex's work process is unusual: at every moment only one employee can work, and the rest have to wait until that employee is done.
The Yooglex office consists of a hall and a room. No more than employees can be in the hall at the same time. Employees form a queue outside the office to enter the hall. Then the following algorithm applies:
- While there are fewer than employees in the hall and at least one employee in the queue, the front employee of the queue enters the hall.
- If the hall is empty, the day is over and the room is locked.
- The employees in the hall choose the one among themselves whose workload for the day is minimal.
- The chosen employee enters the room, works for their time, and leaves the office for the day.
- Go back to step 1.
The Yooglex board wants to evaluate its employees to assign sensible salaries. Two evaluation methods have been proposed.
The first one is simple. For each of the possible permutations of the employee queue and each employee , calculate the time between the moment the first employee in the queue enters the room and the moment employee leaves the room. For each employee, sum these times over all queue permutations. The sums are the final scores.
The second method is even simpler. For the -th employee and each queue permutation, count all employees such that but employee finishes the job before employee . This count is the score for employee .
Choosing between the two methods is pointless, so a third method is proposed: the score of each employee is the product of the scores from the first two methods.
Can you calculate the third method's scores quickly enough?
Input
The first line contains two integers and : the number of employees and the hall capacity (, ).
The second line contains integers : the workloads of the employees (). All are different.
Output
Output integers: the evaluation scores of the employees, in the same order as their workloads in the input. Since the scores can be very large, output them modulo .