report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
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 $A_i$. ### Output - Print a single integer representing the total weight of all subarrays, modulo $10^9+7$. ### Constraints - $1 \le n \le 10^5$. - $1 \le k \le 100$. - $1 \le A_i \le 10^9$. ### Example ``` 6 3 3 1 5 3 2 6 ``` Output: ``` 164 ```
Additional Problems (Level 5)
GCD 2
Brewing potion 9
Amusement park
Growing mushrooms III
Queries on tree 3
Division problem
Watering II
Growing mushrooms II
Squid game
The last Ballade...
Sum of weights
Mushroom harvesting II
Flip
Pairs' value
Sorting queries
Microsoft Paint
Gene bank
Card games
Sequence
Topic
Others
Rating 2000
Solution (0) Solution