#P14810. [CCPC 2024 哈尔滨站] 新能源汽车
[CCPC 2024 哈尔滨站] 新能源汽车
Description
A new energy vehicle is equipped with batteries, where the -th battery has a capacity of units. Each unit of electricity allows the vehicle to travel exactly 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 charging stations. The -th charging station is located at kilometers from the starting point and can only recharge the -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 (), representing the number of test cases.
For each test case, the first line contains two integers (), representing the number of batteries and the number of charging stations, respectively.
The second line contains integers (), representing the capacity of each battery.
The next lines each contain two integers (, ), representing the position of each charging station and the battery it can recharge.
For each test case, it is guaranteed that . Either the sum of or the sum of over all test cases does not exceed .
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
京公网安备 11011102002149号