21509_CoveredWalkway

2022-5-16 18:19| 发布者: Hocassian| 查看: 36| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505353626700-Problem List-采集的数据-后羿采集器.html

Pro.ID

21509

Title

Covered Walkway

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21509

AC

1

Submit

24

Ratio

4.17%

时间&空间限制

  • Time Limit: 20000/10000 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/Others)
  • 描述

    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 x to a point at y, they will charge c+(x-y)2, where c is a constant. Note that it is possible for x=y. If so, then the contractor would simply charge c.

    Given the points along the walkway and the constant c, what is the minimum cost to cover the walkway?

    输入

    There will be several test cases in the input. Each test case will begin with a line with two integers, n (1 ≤ n ≤ 1,000,000) and c (1 ≤ c ≤ 109), where n is the number of points which must be covered, and c is the contractor's constant. Each of the following 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 1 to 109, inclusive. The input will end with a line with two 0s.

    输出

    Description

    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 x to a point at y, they will charge c+(x-y)2, where c is a constant. Note that it is possible for x=y. If so, then the contractor would simply charge c.

    Given the points along the walkway and the constant c, what is the minimum cost to cover the walkway?

    Input

    There will be several test cases in the input. Each test case will begin with a line with two integers, n (1 ≤ n ≤ 1,000,000) and c (1 ≤ c ≤ 109), where n is the number of points which must be covered, and c is the contractor's constant. Each of the following 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 1 to 109, inclusive. The input will end with a line with two 0s.

    Output

    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 64-bit integer.

    Sample Input

    10 5000
    1
    23
    45
    67
    101
    124
    560
    789
    990
    1019
    0 0

    Sample Output

    30726

    Hint

    Very huge input --- the input file is 73M

    Source

    样例输入

    10 5000
    1
    23
    45
    67
    101
    124
    560
    789
    990
    1019
    0 0

    样例输出

    30726

    提示

    Very huge input --- the input file is 73M


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部