City Planning
Time limit1sMemory limit128 MB
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 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 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 . The space station is at , and the remaining lots are numbered as shown below.

Because traffic can only travel on the streets between lots, the distance between lot and the station is .
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 , where 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 (), (), and (), separated by spaces.
The next lines give the cost of building each floor. The -th line contains (), the cost of building the -th floor assuming the floors below it are already built. Building a higher floor always costs more, that is, .
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 and fits in a signed 64-bit integer.