#P15316. [VKOSHP 2025] Strange Sum

[VKOSHP 2025] Strange Sum

Description

Given two non-negative integers nn and xx.

Also, for all 1lrn1 \le l \le r \le n, an integer wl,rw_{l,r} is given.

For an array of integers A=[a1,a2,,an]A = [a_1, a_2, \ldots, a_n], 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 f(A)f(A) over all arrays AA 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 tt -- the number of test cases (1t501 \le t \le 50).

The descriptions of the tt test cases follow.

The first line of each test case contains two integers nn and xx (1n501 \le n \le 50, 1x1091 \le x \le 10^9).

In the ii-th of the following nn lines, there are ni+1n - i + 1 integers wi,i,,wi,nw_{i,i}, \ldots, w_{i,n} (1wi,j1061 \le w_{i,j} \le 10^6).

Output Format

For each test case, output a single integer: the maximum value of f(A)f(A) among all arrays AA 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