Electric poles - MarisaOJ: Marisa Online Judge

Electric poles

Time limit: 1000 ms
Memory limit: 512 MB
A company is responsible for constructing n electric poles for a city. The i-th electric pole has a height of hi. In order to maintain urban aesthetics, the city has imposed a regulation that the company will be charged a cost based on the height difference between two adjacent poles i and i+1, given by ci×|hi−hi+1|. Additionally, the height difference between two neighboring poles must not exceed d. To meet these requirements, the company can increase the height of certain poles. However, increasing the height of the i-th pole by x units will incur a cost of x2. Find the minimum cost required to comply with the city's regulations. ### Input - The first line contains two integer n,d. - The second line contains n−1 integers ci with 1≤i≤n−1. - The third line contain n integers hi. ### Output - Print an integer, the minimum cost. ### Constraints - 1≤n,d,hi≤5000. - 1≤ci≤104. ### Example Input: 54222223514 Output: 15