QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#16031. 玩具装箱

统计

题目描述

今年 8 月,P 教授要去北京看奥运,但是他割舍不下自己的一大堆智力玩具。于是,他决定把所有玩具都装箱运到北京去,这样便可在看比赛的同时摆弄智力玩具。

P 教授使用自己的物体维数压缩器 ODZ(Object Dimension Zipper) 来给玩具装箱。ODZ 可以将任意物品变成一维,再装到一种特殊的一维容器中。P 教授有 $n$ 件玩具,编号为 $1$ 到 $n$。第 $i$ 件玩具经过 ODZ 处理后的一维长度是 $c_i$。为了方便整理,P 教授要求在一个一维容器中的玩具编号是连续的。同时,如果一个一维容器中有多件玩具,那么相邻两件玩具之间应该加入 $1$ 个单位长度的填充物。形式地说,如果将第 $i$ 件到第 $j$ 件玩具放在一个容器中($i < j$),那么容器的长度将为

$$l=j-i+\sum_{k=i}^{j} c_k$$

制作容器的费用与容器的长度有关。根据 P 教授的研究,如果容器长度为 $l$,那么其制作费用为 $(l-L)^2$,其中 $L$ 是一个经过复杂计算推导出的常量。P 教授丝毫不关心容器的数目,并且可以制造出任意长度的容器(甚至超过 $L$),但他希望你帮他求出最小的制作费用。

输入格式

从文件 input.txt 中读入数据,文件的第一行包含玩具数目 $n$ 和常量 $L$,并用一个空格隔开。此后 $n$ 行,每行一个整数 $c_i$,表示第 $i$ 件玩具被 ODZ 处理后的一维长度。输入数据保证 $1\le n\le 50000$ 且 $1\le L,c_i\le 10^7$ 对所有 $i$ 成立。

输出格式

输出文件 output.txt 中仅包含一个整数,表示最小的制作费用。

样例数据

input.txt

5 4
3
4
2
1
4

output.txt

1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.