AcWing 3774. 亮灯时长
原题链接
中等
作者:
lyf11
,
2021-07-20 21:27:50
,
所有人可见
,
阅读 248
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100010;
int n, m;
int a[N], s1[N], s2[N];
int main()
{
int T;
scanf("%d", &T);
while (T -- )
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i ++ ) scanf("%d", &a[i]);
a[ ++ n] = m;
s1[n] = s2[n] = 0;
for (int i = n - 1; i >= 0; i -- )
{
s1[i] = s1[i + 1], s2[i] = s2[i + 1];
if (i % 2 == 0) s1[i] += a[i + 1] - a[i];
else s2[i] += a[i + 1] - a[i];
}
int res = s1[0];
for (int i = 0; i < n; i ++ )
{
int t = a[i + 1] - a[i];
if (t == 1) continue;
res = max(res, s1[0] - s1[i] + s2[i + 1] + t - 1);
}
printf("%d\n", res);
}
return 0;
}