2145.Array Covering

Time Limit: 1s Memory Limit: 256MB

Misha has an array of integers of length n. He wants to choose k different continuous subarrays, so that each element of the array belongs to at least one of the chosen subarrays.

Misha wants to choose the subarrays in such a way that if he calculated the sum of elements for each subarray, and then add up all these sums, the resulting value was maximum possible.

Input Format(From the terminal/stdin)

The first line of input contains two integers: n, k (1 \le n \le 100000, 1 \le k \le n \cdot (n+1)/2)- the number of elements in the array and the number of different subarrays that must be chosen.

The second line contains n integers ai (-50000 \le ai \le 50000)- the elements of the array.

Output Format(To the terminal/stdout)

Output one integer- the maximum possible value Misha can get by choosing k different subarrays.

Sample Input

Copy
5 4
6 -4 -10 -4 7
 · \n
 ·  ·   ·  · \n

Sample Output

Copy
11
  \n

Submit

请先 登录

© 2025 FAQs