CF1000B Light It Up
题目描述
**题目大意:**
有一台灯,这个灯在时间为$0$时打开,$m$时关闭,在$0$到$m$这段时间内有$n$个时间点灯的状态会改变(即开变关,关变开),现在可以在**剩余**的时间点选一个让灯的状态改变一次,求这个灯最大亮着的时间
输入格式
第一行两个整数,$n,m$,$n
输出格式
一个整数,即最大亮着的时间
感谢@守望 提供翻译
说明/提示
In the first example, one of possible optimal solutions is to insert value $ x = 3 $ before $ a_1 $ , so program will be $ [3, 4, 6, 7] $ and time of lamp being lit equals $ (3 - 0) + (6 - 4) + (10 - 7) = 8 $ . Other possible solution is to insert $ x = 5 $ in appropriate place.
In the second example, there is only one optimal solution: to insert $ x = 2 $ between $ a_1 $ and $ a_2 $ . Program will become $ [1, 2, 10] $ , and answer will be $ (1 - 0) + (10 - 2) = 9 $ .
In the third example, optimal answer is to leave program untouched, so answer will be $ (3 - 0) + (7 - 4) = 6 $ .