City Planning

Time limit1sMemory limit128 MB

Summary
Given N residents, transport cost T per distance unit, and increasing per-floor building costs up to K floors per lot, find the minimum total cost of building housing plus 30-year commuting across an infinite grid of lots.
Level

Hard8 of 10

Topics
Binary search, Greedy, Math
Solved
No attempts yet

Problem

A space station is being built on a planet. The station will employ NN people, and they need somewhere to live, so a city is built around the station. The land surrounding the station is divided into equal-sized square lots, and on each lot you may build one apartment building of up to KK floors. Each building has exactly one apartment per floor, and every person lives in a separate apartment.

Each lot is assigned coordinates of the form (x,y)(x, y). The space station is at (0,0)(0, 0), and the remaining lots are numbered as shown below.

Because traffic can only travel on the streets between lots, the distance between lot (x,y)(x, y) and the station is ∣x∣+∣y∣−1|x| + |y| - 1.

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

The buildings will be used for 30 years. Their residents commute to the station, and transporting one resident to and from the station over these 30 years costs T⋅dT \cdot d, where dd is the distance between that resident's building and the station.

The planet is large enough, and the city occupies such a small part of its surface, that the curvature of the surface can be ignored.

Write a program that determines the minimum total cost of building the houses and operating the transportation system for 30 years.

Input

The first line contains the integers NN (1≤N≤10121 \le N \le 10^{12}), TT (1≤T≤500 0001 \le T \le 500\,000), and KK (1≤K≤20 0001 \le K \le 20\,000), separated by spaces.

The next KK lines give the cost of building each floor. The (i+1)(i + 1)-th line contains cic_i (1≤ci≤2⋅1091 \le c_i \le 2 \cdot 10^{9}), the cost of building the ii-th floor assuming the i−1i - 1 floors below it are already built. Building a higher floor always costs more, that is, c1<c2<⋯<cKc_1 < c_2 < \dots < c_K.

Output

Print a single integer: the total cost of building the city and operating the transportation system for 30 years. The answer does not exceed 8⋅10188 \cdot 10^{18} and fits in a signed 64-bit integer.

Examples5

  1. Example 1

    Input
    17 5 4
    100
    107
    114
    121
    
    Expected output
    1778
    
  2. Example 2

    Input
    1 1 1
    5
    
    Expected output
    5
    
  3. Example 3

    Input
    4 10 1
    100
    
    Expected output
    400
    
  4. Example 4

    Input
    5 10 1
    100
    
    Expected output
    510
    
  5. Example 5

    Input
    8 1 2
    1
    2
    
    Expected output
    12