#P14810. [CCPC 2024 哈尔滨站] 新能源汽车

[CCPC 2024 哈尔滨站] 新能源汽车

Description

A new energy vehicle is equipped with nn batteries, where the ii-th battery has a capacity of aia_i units. Each unit of electricity allows the vehicle to travel exactly 11 kilometer. The vehicle can only go forward, not in reverse. You can choose which battery to use for each kilometer driven.

Initially, all batteries are fully charged. During the journey, the vehicle will pass through mm charging stations. The jj-th charging station is located at xjx_j kilometers from the starting point and can only recharge the tjt_j-th battery. Each charging station provides an unlimited amount of electricity.

Your task is to determine the maximum distance the new energy vehicle can travel.

Input Format

The first line contains an integer TT (1T1041\le T\le 10^4), representing the number of test cases.

For each test case, the first line contains two integers n,mn, m (1n,m1051\le n,m\le 10^5), representing the number of batteries and the number of charging stations, respectively.

The second line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (1ai1091\le a_i\le 10^9), representing the capacity of each battery.

The next mm lines each contain two integers xj,tjx_j, t_j (1xj1091\le x_j\le 10^9, 1tjn1\le t_j\le n), representing the position of each charging station and the battery it can recharge.

For each test case, it is guaranteed that 1x1<x2<<xm1091\le x_1<x_2<\ldots<x_m\le 10^9. Either the sum of nn or the sum of mm over all test cases does not exceed 21052\cdot 10^5.

Output Format

For each test case, output an integer in a single line, representing the maximum distance the vehicle can travel.

2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1
12
9