#P15316. [VKOSHP 2025] Strange Sum
[VKOSHP 2025] Strange Sum
Description
Given two non-negative integers and .
Also, for all , an integer is given.
For an array of integers , define
$$f(A) = \sum_{l=1}^{n} \sum_{r=l}^{n} w_{l,r} \cdot \min(a_l, a_{l+1}, \dots, a_r).$$You are required to find the maximum possible value of over all arrays such that
$$a_1 + a_2 + \cdots + a_n = x \quad \text{and} \quad a_i \ge 0.$$Input Format
The input in this problem contains one or more test cases.
The first line contains a single integer -- the number of test cases ().
The descriptions of the test cases follow.
The first line of each test case contains two integers and (, ).
In the -th of the following lines, there are integers ().
Output Format
For each test case, output a single integer: the maximum value of among all arrays such that
$$a_1 + a_2 + \ldots + a_n = x \quad \text{and} \quad a_i \ge 0.$$3
5 10
1 1 1 1 1
1 1 1 1
1 1 1
1 1
1
1 10
1
4 1000000000
1 2 3 4
5 6 7
8 9
10
30
10
14999999995
京公网安备 11011102002149号