欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1000B.Light It Up
Light It Up
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment and turn power off at moment . Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp.
The lamp allows only good programs. Good program can be represented as a non-empty array , where $0 \lt a_1 \lt a_2 \lt \dots \lt a_{|a|} \lt M$. All must be integers. Of course, preinstalled program is a good program.
The lamp follows program in next manner: at moment turns power and light on. Then at moment the lamp flips its state to opposite (if it was lit, it turns off, and vice versa). The state of the lamp flips instantly: for example, if you turn the light off at moment and then do nothing, the total time when the lamp is lit will be . Finally, at moment the lamp is turning its power off regardless of its state.
Since you are not among those people who read instructions, and you don't understand the language it's written in, you realize (after some testing) the only possible way to alter the preinstalled program. You can insert at most one element into the program , so it still should be a good program after alteration. Insertion can be done between any pair of consecutive elements of , or even at the begining or at the end of .
Find such a way to alter the program that the total time when the lamp is lit is maximum possible. Maybe you should leave program untouched. If the lamp is lit from till moment , then its lit for units of time. Segments of time when the lamp is lit are summed up.
Input
First line contains two space separated integers and (, ) — the length of program and the moment when power turns off.
Second line contains space separated integers ($0 \lt a_1 \lt a_2 \lt \dots \lt a_n \lt M$) — initially installed program .
Output
Print the only integer — maximum possible total time when the lamp is lit.
Note
In the first example, one of possible optimal solutions is to insert value before , so program will be and time of lamp being lit equals . Other possible solution is to insert in appropriate place.
In the second example, there is only one optimal solution: to insert between and . Program will become , and answer will be .
In the third example, optimal answer is to leave program untouched, so answer will be .
Samples
3 10
4 6 7
8
2 12
1 10
9
2 7
3 4
6
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |