MemSQL Start[c]UP 3.0 - Round 1
F
Ordering T-Shirts
Codeforces
2800
原题
← EG →
翻译中…

It's another Start[c]up, and that means there are T-shirts to order. In order to make sure T-shirts are shipped as soon as possible, we've decided that this year we're going to order all of the necessary T-shirts before the actual competition. The top $*C*$ contestants are going to be awarded T-shirts, but we obviously don't know which contestants that will be. The plan is to get the T-Shirt sizes of all contestants before the actual competition, and then order enough T-shirts so that no matter who is in the top $*C*$ we'll have T-shirts available in order to award them.

翻译中…

In order to get the T-shirt sizes of the contestants, we will send out a survey. The survey will allow contestants to either specify a single desired T-shirt size, or two adjacent T-shirt sizes. If a contestant specifies two sizes, it means that they can be awarded either size.

翻译中…

As you can probably tell, this plan could require ordering a lot of unnecessary T-shirts. We'd like your help to determine the minimum number of T-shirts we'll need to order to ensure that we'll be able to award T-shirts no matter the outcome of the competition.

翻译中…

Input

翻译中…

Input will begin with two integers $*N*$ and $*C*$ ($1 ≤ *N* ≤ 2·10^{5}$, $1 ≤ *C*$), the number of T-shirt sizes and number of T-shirts to be awarded, respectively.

翻译中…

Following this is a line with $2·*N* - 1$ integers, $*s*_{1}$ through $*s*_{2·*N* - 1}$ $(0 ≤ *s*_{*i*} ≤ 10^{8})$. For odd $*i*$, $*s*_{*i*}$ indicates the number of contestants desiring T-shirt size $((*i* + 1) / 2)$. For even $*i*$, $*s*_{*i*}$ indicates the number of contestants okay receiving either of T-shirt sizes $(*i* / 2)$ and $(*i* / 2 + 1)$. $*C*$ will not exceed the total number of contestants.

翻译中…

Output

翻译中…

Print the minimum number of T-shirts we need to buy.

翻译中…

Note

翻译中…

In the first example, we can buy $100$ of each size.

翻译中…

样例

Input #1
2 200
100 250 100
Output #1
200
InputCopy OutputCopy
Input #2
4 160
88 69 62 29 58 52 44
Output #2
314
InputCopy OutputCopy
题目信息
题号
859F
时间限制
2 s
内存限制
256 MB
标签
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。