CF1428E.Carrots for Rabbits

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought nn carrots with lengths a1,a2,a3,…,ana_1, a_2, a_3, \ldots, a_n. However, rabbits are very fertile and multiply very quickly. Zookeeper now has kk rabbits and does not have enough carrots to feed all of them. To solve this problem, Zookeeper decided to cut the carrots into kk pieces. For some reason, all resulting carrot lengths must be positive integers.

Big carrots are very difficult for rabbits to handle and eat, so the time needed to eat a carrot of size xx is x2x^2.

Help Zookeeper split his carrots while minimizing the sum of time taken for rabbits to eat the carrots.

新加坡动物园里有一些兔子。为了喂养它们,饲养员购买了 nn 根胡萝卜,长度分别为 a1,a2,a3,…,ana_1, a_2, a_3, \ldots, a_n。然而,兔子繁殖能力极强,数量增长很快。如今饲养员有 kk 只兔子,但胡萝卜数量不足,无法喂饱所有兔子。为解决这一问题,饲养员决定将胡萝卜切成总共 kk 段。出于某种原因,所有切分后胡萝卜的长度必须为正整数。

大块胡萝卜对兔子而言很难处理和进食,因此兔子吃掉一根长度为 xx 的胡萝卜所需时间为 x2x^2。

请帮助饲养员切分胡萝卜,使得所有兔子吃完胡萝卜所需的总时间最小。

输入格式

The first line contains two integers nn and kk (1≤n≤k≤105)(1 \leq n \leq k \leq 10^5): the initial number of carrots and the number of rabbits.

The next line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤106)(1 \leq a_i \leq 10^6): lengths of carrots.

It is guaranteed that the sum of aia_i is at least kk.

第一行包含两个整数 nn 和 kk (1≤n≤k≤105)(1 \leq n \leq k \leq 10^5):初始胡萝卜的数量和兔子的数量。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤106)(1 \leq a_i \leq 10^6):胡萝卜的长度。

保证所有 aia_i 的总和至少为 kk。

输出格式

Output one integer: the minimum sum of time taken for rabbits to eat carrots.

输出一个整数:兔子吃胡萝卜所需时间的最小总和。

输入输出样例

  • 输入#1

    3 6
    5 3 1

    输出#1

    15
  • 输入#2

    1 4
    19

    输出#2

    91

说明/提示

For the first test, the optimal sizes of carrots are 1,1,1,2,2,2{1,1,1,2,2,2}. The time taken is 12+12+12+22+22+22=151^2+1^2+1^2+2^2+2^2+2^2=15

For the second test, the optimal sizes of carrots are 4,5,5,5{4,5,5,5}. The time taken is 42+52+52+52=914^2+5^2+5^2+5^2=91.

对于第一个测试用例,胡萝卜的最优尺寸为 1,1,1,2,2,2{1,1,1,2,2,2}。所用时间为 12+12+12+22+22+22=151^2+1^2+1^2+2^2+2^2+2^2=15。

对于第二个测试用例,胡萝卜的最优尺寸为 4,5,5,5{4,5,5,5}。所用时间为 42+52+52+52=914^2+5^2+5^2+5^2=91。

输入解题思路,AI测评打分。不知道怎么写?

首页