포럼
문제 ICPC00330

G. Generator Grid

설명

The volcanic island of Fleeland has never had a proper electric net, but finally the Biomass Alternative Power Conglomerate (BAPC) has agreed to build the island's power plants and network.

On the island's coast are its \(n\) cities. The BAPC has surveyed the cities and proposed \(m\) of them as possible locations for a power plant, with the \(i\)th proposal stating that the company can build a plant in city \(c_i\) for cost \(a_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 \(1 \leq i < n\), the company can build power lines between cities \(i\) and \(i+1\) for a cost of \(b_i\), and between cities \(n\) and \(1\) for a cost of \(b_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?

제약
입력 형식

The input consists of:
- One line containing two integers \(n\) (\(3\leq n \leq 10^5\)) and \(m\) (\(1\leq m \leq n\)), the number of cities and the number of possible locations for a power plant.
- Then follow \(m\) lines, the \(i\)th of which contains \(c_i\) (\(1 \leq c_i \leq n\)) and \(a_i\) ($1
\leq a_i \leq 10^9\(), the \)i$th possible location for a power plant, and the cost to build it.
- Then follows a line containing \(n\) integers \(b_i\) (\(1 \leq b_i \leq 10^9\)), the costs of building the power lines.

The values of \(c_1,\ldots,c_m\) 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
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC BAPC 2020

평가 및 의견

G. Generator Grid

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

G. Generator Grid

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8