mrh-acmer

B. Light It Up

 

进行的操作一定在亮区间,从后往前遍历在某区间操作后的收益flag最大就行
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
#pragma optimize O3
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#define debug(x) cerr << #x << " : " << x;
const int infint = (ll)1e9;
const ll inf = (ll)1e18;
const int maxn = 100005;
int main()
{
    int n, m, a[maxn], flag = 0, up = 0, maxx = 0;
    a[0] = 0;
    cin >> n >> m;
    a[n+1] = m;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if(i % 2 == 1)
        {
            up += (a[i] - a[i-1]);
        }
        else if(i == n && i%2 == 0)
            up += m - a[i];
    }
    for(int i = n; i>0; i--)
    {
        if(i % 2 == 0)
        {
            flag -= (a[i+1] - a[i]);
        }
        else
        {
            flag += (a[i+1] - a[i]);
        }
        maxx = max(flag , maxx);
    }
    if(maxx <= 0) cout << up << endl;
    else cout << up + maxx -1<< endl;



}

 

posted on 2018-06-28 16:52 Cynicism-m 阅读(...) 评论(...) 编辑 收藏

分类:

ACM

技术点:

相关文章:

  • 2021-08-04
  • 2021-12-06
  • 2021-04-11
  • 2022-01-03
  • 2021-08-15
  • 2022-01-17
  • 2021-12-03
  • 2021-10-19
猜你喜欢
  • 2021-07-07
  • 2020-04-28
  • 2021-10-26
  • 2021-12-13
  • 2022-01-02
  • 2021-10-22
  • 2021-10-19
相关资源
相似解决方案