K-mins
Time limit2sMemory limit1024 MB
Given an array of distinct integers, find the sum of the K-th smallest value over every subarray. Subarrays shorter than K contribute 0.
- Level
Medium6 of 10
- Topics
- Divide and conquer, Sorting, Array
- Solved
- No attempts yet
Problem
A sequence of length is given. For any two integers and with , holds.
For two integers and with , define as follows.
is the -th smallest value among .
If the length of the interval, , is less than , then .
Compute .
Input
The first line contains the number of elements and the integer , separated by a space. (; )
The second line contains the integers , separated by spaces. ()
Output
Print the value of .