QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 512 MB Total points: 100

#1611. Addition

Statistics

Kele has a sequence $A$ of $n$ positive integers, but she feels the numbers in $A$ are too small, which makes her unhappy.

Therefore, she chooses $m$ intervals $[l_i, r_i]$ and two positive integers $a$ and $k$. She intends to select exactly $k$ intervals from these $m$ intervals and perform an interval addition operation of $a$ on each selected interval. (Each interval can be selected at most once.)

Performing an addition of $a$ on an interval $[l, r]$ is defined as changing $A_i$ to $A_i + a$ for all $i \in [l, r]$.

Now, Kele wants to know how to choose the intervals such that the minimum value of the sequence after the operations is as large as possible, i.e., to maximize $\min \{ A_i \}$.

Input

The first line contains an integer representing the number of test cases.

For each test case, the first line contains four integers $n, m, k, a$.

The second line contains $n$ integers describing the sequence $A$.

The next $m$ lines each contain two integers $l_i, r_i$ describing each interval. It is guaranteed that all intervals are distinct.

Output

For each test case, output an integer representing the maximum possible value of the minimum element of the sequence after the operations.

Examples

Input 1

1
3 3 2 1
1 3 2
1 1
1 3
3 3

Output 1

3

Note 1

Choose to add $1$ to the intervals $[1, 1]$ and $[1, 3]$.

Subtasks

Test Case ID $\sum n$ $\sum m$
$1$ $\leq 20$ $\leq 20$
$2$ $\leq 20$ $\leq 20$
$3$ $\leq 2000$ $\leq 2000$
$4$ $\leq 2000$ $\leq 2000$
$5$ $\leq 2000$ $\leq 2000$
$6$ $\leq 2000$ $\leq 2000$
$7$ $\leq 2 \times 10^5$ $\leq 2 \times 10^5$
$8$ $\leq 2 \times 10^5$ $\leq 2 \times 10^5$
$9$ $\leq 2 \times 10^5$ $\leq 2 \times 10^5$
$10$ $\leq 2 \times 10^5$ $\leq 2 \times 10^5$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.