#ds604. 第k大查询
第k大查询
K-th Largest Query
Problem Description
Given a permutation of , consider all intervals satisfying . For each such interval, take the -th largest element among the numbers inside it, and output the sum of all these -th largest elements.
Input Format
The first line contains two integers .
The next line contains integers .
Output Format
Output one line containing a single integer: the answer.
Sample Input
5 2
1 2 3 4 5
Sample Output
30
Sample Explanation
The intervals have as their nd largest; the intervals have as their nd largest; the intervals have as their nd largest; the interval has as its nd largest.
Constraints
There are test cases in total.
- Test points : .
- Test points : .
- Test points : .
- Test points : .
- For of the data: .
Hint
See the files attached to this problem.