QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 2048 MB 満点: 100

#16832. Memories of Passport Stamps

統計

你刚刚拿到了一本崭新的护照,里面全是空白页,等待着出入境官员盖章。遗憾的是,因为你的护照页数太多,出入境官员懒得高效地利用这些页面,所以你可能需要比想象中更早地更换新护照。

你准备了一些旅行。对于每一次旅行,当你通过护照检查处时,出入境官员会寻找一些连续的、均未盖章的页面,然后将它们全部盖章。因为官员很懒,所以无法保证哪些连续的页面会被盖章。

现在,你的护照上已经没有足够的连续空白页来满足下一次旅行了,所以你正在申请新护照。在此之前,你决定翻看你的护照,回忆你度过的所有愉快旅行。在这些旅行中,你最不喜欢的部分就是等待出入境官员给你的护照盖章。

翻阅护照时,你记起自己一共进行了 $k$ 次旅行。护照上现在有 $n$ 个连续的已盖章页面区间。请问最小的 $s$ 是多少,使得每位官员都有可能盖下介于 $0$ 到 $s$ 之间(均包含)的任意页数,从而恰好得到你现在护照上所拥有的这些已盖章页面区间?不同的官员可以盖不同数量的页数,且官员允许盖 $0$ 页。

输入格式

第一行包含两个整数 $n$($1 \le n \le 10^5$)和 $k$($n \le k \le 10^{18}$),其中 $n$ 是连续的已盖章页面区间数量,$k$ 是你进行的旅行次数。

接下来的 $n$ 行,每行包含一个整数 $p$($1 \le p \le 10^{18}$),表示你护照中某个区间内连续已盖章的页面数量。保证你的护照中总共最多有 $10^{18}$ 页被盖章。

输出格式

输出一个整数,即最小的 $s$,使得每位官员都有可能盖下介于 $0$ 到 $s$ 之间的页数,从而恰好得到你现在护照上所拥有的这些已盖章页面区间。

样例

输入样例 1

3 5
9
12
5

输出样例 1

6

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.