atcoder#ARC129E. [ARC129E] Yet Another Minimization
[ARC129E] Yet Another Minimization
Score : points
Problem Statement
Snuke is making an integer sequence of length : . For each (), there are candidates for the value of : the -th of them is . Choosing incurs a cost of .
Additionally, after deciding , a cost of is incurred for each ().
Find the minimum possible total cost incurred.
Constraints
- $1 \leq A_{i,1} < A_{i,2} < \cdots < A_{i,M} \leq 10^6$
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3 2
1 1
5 2
2 3
9 4
7 2
8 2
1 5
3
28
An optimal choice is . The individual costs incurred here are as follows.
- Choosing for incurs a cost of .
- Choosing for incurs a cost of .
- Choosing for incurs a cost of ..
- For , a cost of is incurred.
- For , a cost of is incurred.
- For , a cost of is incurred.
10 3
19 2517
38 785
43 3611
3 681
20 758
45 4745
6 913
7 2212
22 536
4 685
27 148
36 2283
25 3304
36 1855
43 2747
11 1976
32 4973
43 3964
3 4242
16 4750
50 24
4 4231
22 1526
31 2152
15 2888
28 2249
49 2208
31 3127
40 3221
47 4671
24 6 16 47 42 50 35 43 47
29 18 28 24 27 25 33 12
5 43 20 9 39 46 30
40 24 34 5 30 21
50 6 21 36 5
50 16 13 13
2 40 15
25 48
20
27790
2 2
1 1
10 10
1 1
10 10
100
2