CF1765D.Watch the Videos

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Monocarp wants to watch nn videos. Each video is only one minute long, but its size may be arbitrary. The ii-th video has the size aia_i megabytes. All videos are published on the Internet. A video should be downloaded before it can be watched. Monocarp has poor Internet connection — it takes exactly 11 minute to download 11 megabyte of data, so it will require aia_i minutes to download the ii-th video.

Monocarp's computer has a hard disk of mm megabytes. The disk is used to store the downloaded videos. Once Monocarp starts the download of a video of size ss, the ss megabytes are immediately reserved on a hard disk. If there are less than ss megabytes left, the download cannot be started until the required space is freed. Each single video can be stored on the hard disk, since ai≤ma_i \le m for all ii. Once the download is started, it cannot be interrupted. It is not allowed to run two or more downloads in parallel.

Once a video is fully downloaded to the hard disk, Monocarp can watch it. Watching each video takes exactly 11 minute and does not occupy the Internet connection, so Monocarp can start downloading another video while watching the current one.

When Monocarp finishes watching a video, he doesn't need it on the hard disk anymore, so he can delete the video, instantly freeing the space it occupied on a hard disk. Deleting a video takes negligible time.

Monocarp wants to watch all nn videos as quickly as possible. The order of watching does not matter, since Monocarp needs to watch all of them anyway. Please calculate the minimum possible time required for that.

Monocarp 想要观看 nn 个视频。每个视频时长恰好为 1 分钟,但其大小可以是任意的。第 ii 个视频的大小为 aia_i 兆字节(MB)。所有视频均发布在互联网上,而一个视频必须先被下载,才能被观看。Monocarp 的网络连接较差——下载数据的速度恰好为每分钟 1 兆字节,因此下载第 ii 个视频需要 aia_i 分钟。

Monocarp 的电脑硬盘容量为 mm 兆字节,用于存储已下载的视频。一旦 Monocarp 开始下载一个大小为 ss 的视频,硬盘上会立即预留出 ss 兆字节的空间。若剩余空间不足 ss 兆字节,则无法启动该下载,直至释放出所需空间为止。由于对所有 ii 均有 ai≤ma_i \le m,因此每个视频均可单独存入硬盘。一旦下载开始,便不可中断。同时,不允许并行运行两个或更多下载任务。

当一个视频被完整下载至硬盘后,Monocarp 即可开始观看它。观看每个视频恰好耗时 1 分钟,且不占用网络连接,因此 Monocarp 可以在观看当前视频的同时,开始下载另一个视频。

当 Monocarp 观看完一个视频后,便不再需要该视频保存在硬盘上,因此他可以立即将其删除,从而瞬时释放其所占的硬盘空间。删除视频所耗时间可忽略不计。

Monocarp 希望以尽可能短的时间观看全部 nn 个视频。观看顺序无关紧要,因为 Monocarp 最终必须观看所有视频。请计算完成这一目标所需的最短可能时间。

输入格式

The first line contains two integers nn and mm (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5; 1≤m≤1091 \le m \le 10^9) — the number of videos Monocarp wants to watch and the size of the hard disk, respectively.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤m1 \le a_i \le m) — the sizes of the videos.

第一行包含两个整数 nn 和 mm(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5;1≤m≤1091 \le m \le 10^9)—— 分别表示 Monocarp 想观看的视频数量以及硬盘容量。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤m1 \le a_i \le m)—— 表示各视频的大小。

输出格式

Print one integer — the minimum time required to watch all nn videos.

输出一个整数——观看全部 nn 个视频所需的最短时间。

输入输出样例

  • 输入#1

    5 6
    1 2 3 4 5

    输出#1

    16
  • 输入#2

    5 5
    1 2 3 4 5

    输出#2

    17
  • 输入#3

    4 3
    1 3 2 3

    输出#3

    12

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

首页