102164: [AtCoder]ABC216 E - Amusement Park

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $500$ points

Problem Statement

Takahashi has come to an amusement park.
The park has $N$ attractions. The fun of the $i$-th attraction is initially $a_i$.

When Takahashi rides the $i$-th attraction, the following sequence of events happens.

  • Takahashi's satisfaction increases by the current fun of the $i$-th attraction.
  • Then, the fun of the $i$-th attraction decreases by $1$.

Takahashi's satisfaction is initially $0$. He can ride the attractions at most $K$ times in total in any order.
What is the maximum possible value of satisfaction Takahashi can end up with?

Other than riding the attractions, nothing affects Takahashi's satisfaction.

Constraints

  • $1 \leq N \leq 10^5$
  • $1 \leq K \leq 2 \times 10^9$
  • $1 \leq A_i \leq 2 \times 10^9$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$ $K$
$A_1$ $A_2$ $\dots$ $A_N$

Output

Print the maximum possible value of satisfaction that Takahashi can end up with.


Sample Input 1

3 5
100 50 102

Sample Output 1

502

Takahashi should ride the first attraction twice and the third attraction three times.
He will end up with the satisfaction of $(100+99)+(102+101+100)=502$.
There is no way to get the satisfaction of $503$ or more, so the answer is $502$.


Sample Input 2

2 2021
2 3

Sample Output 2

9

Takahashi may choose to ride the attractions fewer than $K$ times in total.

Input

题意翻译

高桥去游乐园玩。 有 $n$ 个游乐设施,每次玩时满意度加上此设施的乐趣值,同时设施的乐趣值减一,直到变成 $0$。 一个设施可以玩多次,求一共玩 $k$ 次后高桥满意度的最大值。 $1 \leq n \leq 1 \times 10^5$; $1 \leq k,a_i \leq 2 \times 10^9$。

Output

得分:500分

问题描述

高桥来到了一个游乐园。
这个游乐园有N个游乐设施。第i个游乐设施的初始“乐趣”为$a_i$。

当高桥乘坐第i个游乐设施时,会发生以下一系列事件。

  • 高桥的“满意度”增加当前第i个游乐设施的“乐趣”。
  • 然后,第i个游乐设施的“乐趣”减少1。

高桥的满意度最初为0。他可以以任意顺序总共乘坐游乐设施最多$K$次。
高桥最终可能获得的最大满意度是多少?

除了乘坐游乐设施外,其他任何事情都不会影响高桥的满意度。

约束

  • $1 \leq N \leq 10^5$
  • $1 \leq K \leq 2 \times 10^9$
  • $1 \leq A_i \leq 2 \times 10^9$
  • 输入中的所有值都是整数。

输入

输入按照以下格式从标准输入给出:

$N$ $K$
$A_1$ $A_2$ $\dots$ $A_N$

输出

打印高桥最终可能获得的最大满意度。


样例输入1

3 5
100 50 102

样例输出1

502

高桥应该乘坐第一个游乐设施两次和第三个游乐设施三次。
他的满意度最终将达到$(100+99)+(102+101+100)=502$。
没有其他方法可以获得503或以上的满意度,因此答案是502。


样例输入2

2 2021
2 3

样例输出2

9

高桥可以选择总共乘坐游乐设施少于$K$次。

加入题单

算法标签: