#P9691. [GDCPC2023] Base Station Construction
[GDCPC2023] 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 .