Sum the contest penalty over all n! read orders, where after reading k problems you always solve the read-but-unsolved problem with the smallest solving time.
Hard8CombinatoricsGreedySortingMathNo attempts yetTime limit2sMemory limit512 MBYou are taking part in the ACM International Collegiate Programming Contest (ICPC), where you have to solve all n problems. Reading a problem takes no time, and once you have read it you know exactly how long solving it takes. Solving problem i takes ti.
Your strategy during the contest is this.
The submission time of a problem is the time that has passed when you finish solving it, that is, the total solving time of every problem you have solved up to and including that one. The penalty of the contest is the sum of the submission times of all n problems.
One read order is one permutation of the n problems. You read the first k problems of the permutation at the start, and after solving a problem you read the next problem of the permutation. The penalty depends on the read order, and there are n! read orders. Add up the penalty over all n! of them and print the sum modulo 109+7.
When several read problems tie for the smallest solving time in step 2, the penalty is the same whichever one you choose, so the answer is uniquely determined.
The first line contains two integers n and k separated by a space (1≤k≤n≤300).
The i-th of the next n lines contains one integer ti (1≤ti≤106).
Print on one line the sum of the penalties over all read orders, modulo 109+7.