#P9691. [GDCPC 2023] Base Station Construction
[GDCPC 2023] Base Station Construction
题目描述
China Mobile Shenzhen Branch was registered in . Four years later, Guangdong Collegiate Programming Contest was held for the first time. China Mobile Shenzhen Branch, along with Guangdong Collegiate Programming Contest, witnesses the prosperity and development of the computer industry in Guangdong.

During the construction of a communication line, it is critical to carefully choose the locations for base stations. The distance from west to east of a city is kilometers. The engineers have investigated the cost to build a base station at kilometers from west to east, which are respectively.
To ensure communication quality for the residents, the locations of base stations also need to meet requirements. The -th requirement can be represented as a pair of integers and (), indicating that there must be at least base station between kilometers and kilometers (both inclusive) from west to east.
As the chief engineer, you need to decide the number of base stations to build and their locations, and finally calculate the minimum total cost to satisfy all requirements.
输入格式
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:
The first line contains an integer () indicating the distance from west to east of the city.
The second line contains integers () where indicates the cost to build a base station at kilometers from west to east.
The third line contains an integer () indicating the number of requirements.
For the following lines, the -th line contains two integers and () indicating that there must be at least base station between kilometers and kilometers (both inclusive) from west to east.
It's guaranteed that neither the sum of nor the sum of of all test cases will exceed .
输出格式
For each test case output one line containing one integer indicating the minimum total cost to satisfy all requirements.
2
5
3 2 4 1 100
3
1 3
2 4
5 5
5
7 3 4 2 2
3
1 4
2 3
4 5
102
5
提示
For the first sample test case the optimal solution is to build base stations at kilometers and kilometers from west to east. The total cost is .
For the second sample test case the optimal solution is to build base stations at kilometers and kilometers from west to east. The total cost is .