#P7640. [BalticOI 2006] CITY PLANNING (Day 2)

[BalticOI 2006] CITY PLANNING (Day 2)

Description

A space station will be built on a planet. The station will employ NN people. They must live somewhere, so a city will be built around the station. The land around the station is divided into equal-sized square blocks, and on each block it is possible to build an apartment building with at most KK floors. Each building must contain exactly one apartment on each floor, and each person must live in a separate apartment.

The space station is located at coordinates (0,0)(0,0). The other blocks are numbered as shown below: TuLi

Because traffic between blocks can only move along streets, the distance from block (x,y)(x,y) to the space station is x+y1|x|+|y|-1 units.

The cost of building a building equals the sum of the costs of building its floors. As is well known, the cost of building a floor depends only on the floor height, not on the building location.

The buildings will be used for 3030 years. The people living in these buildings will commute to the space station for work. Over these 3030 years, transporting one person to and from the station will cost TdT \cdot d, where dd is the distance from the person’s building to the space station.

We may assume that the planet is large enough and the city occupies only a small part of its surface, so we do not need to consider the curvature of the planet.

Your task is to write a program to determine the minimum total cost over 3030 years for building the housing and operating the transportation system.

Input Format

The first line contains integers NN, TT, and KK. The next KK lines specify the construction cost per apartment for each floor. Line i+1i+1 contains an integer cic_i, meaning the cost to build one apartment on the ii-th floor (assuming all floors below the (i1)(i-1)-th have already been built).

It is well known that building a higher floor is always more expensive than building a lower floor: c1<c2<<ckc_1<c_2< \cdots <c_k.

Output Format

The only line contains one integer: the total cost of building the city and operating the transportation system for 3030 years.

17 5 4
100
107
114
121
1778

Hint

Constraints

For 100%100\% of the testdata, 1N10121 \le N \le 10^{12}, 1T5×1051 \le T \le 5 \times 10^5, 1K200001 \le K \le 20000, 1ci2×1091 \le c_i \le 2 \times 10^9. It is guaranteed that the answer does not exceed 8×10188 \times 10^{18} (that is, it fits in a 64-bit signed integer).

Notes

From Baltic Olympiad in Informatics 2006 Day 2:City.
Translated and organized by @求学的企鹅.

Translated by ChatGPT 5