Processing math: 100%
Sum of weights - MarisaOJ: Marisa Online Judge

Sum of weights

Time limit: 1000 ms
Memory limit: 256 MB
Given an array A of n integers, the weight of a consecutive subarray is defined as the sum of the k largest elements in the subarray, or the sum of all elements if the subarray has fewer than k elements. Compute the total weight of all consecutive subarrays of A. ### Input - The first line contains two integers n and k. - The second line contains n integers Ai. ### Output - Print a single integer representing the total weight of all subarrays, modulo 109+7. ### Constraints - 1≤n≤105. - 1≤k≤100. - 1≤Ai≤109. ### Example 63315326 Output: 164