AlgoLensArena
ContestlərProblemlərOtaqlar
Vizualizator
← Məsələlər

BAPC20-095.\problemyamlname

Medium · 1 s · 256 MB

  • icpc
  • bapc
  • 2020

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 nnn cities. The BAPC has surveyed the cities and proposed mmm of them as possible locations for a power plant, with the iiith proposal stating that the company can build a plant in city cic_ici​ for cost aia_iai​.

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≤i<n1 \leq i < n1≤i<n, the company can build power lines between cities iii and i+1i+1i+1 for a cost of bib_ibi​, and between cities nnn and 111 for a cost of bnb_nbn​. 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?

Giriş formatı

The input consists of:

• One line containing two integers nnn (3≤n≤1053\leq n \leq 10^53≤n≤105) and mmm (1≤m≤n1\leq m \leq n1≤m≤n), the number of cities and the number of possible locations for a power plant.

• Then follow mmm lines, the iiith of which contains cic_ici​ (1≤ci≤n1 \leq c_i \leq n1≤ci​≤n) and aia_iai​ (1≤ai≤1091 \leq a_i \leq 10^91≤ai​≤109), the iiith possible location for a power plant, and the cost to build it.

• Then follows a line containing nnn integers bib_ibi​ (1≤bi≤1091 \leq b_i \leq 10^91≤bi​≤109), the costs of building the power lines.

The values of c1,…,cmc_1,\ldots,c_mc1​,…,cm​ are unique and given in strictly increasing order.

Çıxış formatı

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

Qeyd

Source: Benelux Algorithm Programming Contest 2020 · Author: Timon Knigge · License: CC BY-SA 4.0 · Original: https://bapc.eu · Statement adapted for AlgoLens and shared under the same license. · 5 of the 15 original test cases (the largest) are omitted here to keep the problem lightweight.

Nümunələr

Giriş #1

3 2
1 100
2 200
150 300 150

Çıxış #1

400

Giriş #2

3 2
1 100
2 200
300 300 150

Çıxış #2

450