33OJ
登录 注册

#P17550. [JAG 2026 Summer Camp #2] Buttons

    ID: 20276 远端评测题 4000ms 2048MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>动态规划 DP线段树动态规划优化ICPC2026

[JAG 2026 Summer Camp #2] Buttons

Problem Description

Consider a sequence X=(X1,X2,…,XN)X=(X_1,X_2,\ldots,X_N) of length NN. Initially, all elements of XX are zero. You are also given a sequence P=(P1,P2,…,PN)P=(P_1,P_2,\ldots,P_N) of NN nonnegative integers.

There are MM buttons. Pressing the ii-th button once increases XjX_j by 11 for every integer jj satisfying Li≤j≤RiL_i\le j\le R_i. Each button may be pressed any number of times, including zero.

The buttons must be pressed so that, for every i=1,2,…,Ni=1,2,\ldots,N, the final value of XiX_i is at most KK.

Find the maximum possible value of

∑i=1NPiXi\sum_{i=1}^{N}P_iX_i

among all valid ways of pressing the buttons.

Input Format

The input contains one or more test cases. The first line of the input contains an integer tt (1≤t≤1051\le t\le 10^5), which is the number of test cases. The descriptions of the tt test cases follow, each in the following format.

N M K
P_1 P_2 ... P_N
L_1 R_1
...
L_M R_M

The first line of each test case contains three integers NN, MM, and KK, representing the length of the sequence XX, the number of buttons, and the upper bound for each element of XX, respectively. They satisfy 1≤N,M,K≤2×1051\le N,M,K\le 2\times 10^5.

The second line contains NN integers P1,P2,…,PNP_1,P_2,\ldots,P_N. For each ii (1≤i≤N1\le i\le N), the integer PiP_i represents the weight of XiX_i and satisfies 0≤Pi≤1070\le P_i\le 10^7.

Each of the following MM lines contains two integers LjL_j and RjR_j (1≤j≤M1\le j\le M). They satisfy 1≤Lj≤Rj≤N1\le L_j\le R_j\le N and represent the interval affected by the jj-th button.

The sum of NN, MM, and KK over all test cases does not exceed 6×1056\times 10^5 each.

Output Format

Output tt lines. For each test case, output the maximum possible value of ∑i=1NPiXi\sum_{i=1}^{N}P_iX_i among all valid ways of pressing the buttons, in a separate line.

3
4 3 2
3 1 4 2
1 2
2 3
4 4
1 3 5
7
1 1
1 1
1 1
12 7 1
5 0 8 2 7 1 6 3 9 4 0 10
1 3
2 5
4 6
6 8
9 12
3 7
8 10
14
35
50

Hint

In the first test case, pressing the second and third buttons twice each results in X=(0,2,2,2)X=(0,2,2,2). The resulting sum is then 3×0+1×2+4×2+2×2=143\times 0+1\times 2+4\times 2+2\times 2=14, which is the maximum possible value.