PivotOJ

Generators

시간 제한: 2000ms메모리 제한: 512MB출처: BAPC 2020BOJ 20335

문제

The volcanic island of Fleeland has never had a proper electric net, but finally the administration of the island have agreed to build the island's power plants and network.

On the island's coast are its nn cities. The administration has surveyed the cities and proposed mm of them as possible locations for a power plant, with the iith proposal stating that the company can build a plant in city cic_i for cost aia_i.

These power plants are very modern and a single plant could power the whole island, but the volcano makes building power lines across the island a dangerous affair. For 1i<n1 \leq i < n, the company can build power lines between cities ii and i+1i+1 for a cost of bib_i, and between cities nn and 11 for a cost of bnb_n. A city will receive power if it contains a power plant or is connected to a city with a power plant via power lines.

What is the cheapest way to power all the cities on the island?

입력

  • One line containing two integers nn (3n1053\leq n \leq 10^5) and mm (1mn1\leq m \leq n), the number of cities and the number of possible locations for a power plant.
  • Then follow mm lines, the iith of which contains cic_i (1cin1 \leq c_i \leq n) and aia_i (1ai1091 \leq a_i \leq 10^9), the iith possible location for a power plant, and the cost to build it.
  • Then follows a line containing nn integers bib_i (1bi1091 \leq b_i \leq 10^9), the costs of building the power lines.

The values of c1,,nc_{1,\ldots,n} are unique and given in strictly increasing order.

출력

Output the minimal cost of powering all cities on the island.

예제

예제 1

입력
3 2
1 100
2 200
150 300 150
출력
400

예제 2

입력
3 2
1 100
2 200
300 300 150
출력
450
코드를 제출하려면 로그인하세요.