#P2605. Optimal Communication Base Station Placement

    ID: 15874 Type: Default 1000ms 256MiB

Optimal Communication Base Station Placement

Optimal Communication Base Station Placement

There are NN villages arranged on a straight line. The position of the first village is 00, and for every i>1i>1, the distance from the first village to the ii-th village is given by DiD_i. You are allowed to build at most KK communication base stations. Building a base station at the ii-th village costs CiC_i. A village ii is considered to be covered if there exists a base station built in some village jj such that $$|\text{pos}_i-\text{pos}_j|\le S_i.$$ If village ii is not covered, a compensation cost of WiW_i must be paid. The goal is to choose locations for the base stations (a set of villages of size at most KK) so that the total cost (the sum of building costs and any necessary compensations) is minimized.

inputFormat

The first line contains two integers $N$ and $K$, where $N$ is the number of villages and $K$ is the maximum number of base stations that can be built.

The second line contains $N-1$ integers: $D_2, D_3, \dots, D_N$, where $D_i$ is the distance from the first village (position $0$) to the $i$-th village.

The following $N$ lines each contain three integers $C_i$, $S_i$, and $W_i$, which denote the cost to build a base station at village $i$, the coverage distance for village $i$, and the compensation cost if village $i$ is not covered, respectively.

outputFormat

Output a single integer representing the minimum total cost.

sample

3 1
10 20
100 5 50
150 15 30
200 10 40
120