eolymp
bolt
Try our new interface for solving problems
Məsələlər

Covered Walkway

Covered Walkway

Your university wants to build a new walkway, and they want at least part of it to be covered. There are certain points which must be covered. It doesn’t matter if other points along the walkway are covered or not. The building contractor has an interesting pricing scheme. To cover the walkway from a point at \textbf{x} to a point at \textbf{y}, they will charge \textbf{c+(x-y)^2}, where \textbf{c} is a constant. Note that it is possible for \textbf{x=y}. If so, then the contractor would simply charge \textbf{c}. Given the points along the walkway and the constant \textbf{c}, what is the minimum cost to cover the walkway? \InputFile There will be several test cases in the input. Each test case will begin with a line with two integers, \textbf{n} (\textbf{1} ≤ \textbf{n} ≤\textbf{1000000}) and \textbf{c} (\textbf{1} ≤ \textbf{c} ≤ \textbf{10^9}), where \textbf{n} is the number of points which must be covered, and \textbf{c} is the contractor’s constant. Each of the following \textbf{n} lines will contain a single integer, representing a point along the walkway that must be covered. The points will be in order, from smallest to largest. All of the points will be in the range from \textbf{1} to \textbf{10^9}, inclusive. The input will end with a line with two \textbf{0}s. \OutputFile For each test case, output a single integer, representing the minimum cost to cover all of the specified points. Output each integer on its own line, with no spaces, and do not print any blank lines between answers. All possible inputs yield answers which will fit in a signed \textbf{64}-bit integer.
Zaman məhdudiyyəti 10 saniyə
Yaddaşı istafadə məhdudiyyəti 128 MiB
Giriş verilənləri #1
10 5000
1
23
45
67
101
124
560
789
990
1019
0 0
Çıxış verilənləri #1
30726
Mənbə The University of Chicago Invitational Programming Contest 2012 15 April 2012