제출 #1199151

#제출 시각아이디문제언어결과실행 시간메모리
1199151iamhereforfunGlobal Warming (CEOI18_glo)C++20
0 / 100
18 ms1092 KiB
// IamHereForFun //

#include <bits/stdc++.h>

using namespace std;

#define LSOne(S) ((S) & -(S))

const int N = 1e5 + 5;
const int M = 513;
const int K = 4;
const int LG = 20;
const long long INF = -1e18;
const int MOD = 1e9 + 7;
const int B = 50;

int n, d, a[N], val[N], ans = 0;
vector<int> v;

void solve()
{
    cin >> n >> d;
    for (int x = 0; x < n; x++)
    {
        cin >> a[x];
    }
    for (int x = n - 1; x >= 0; x--)
    {
        int i = -a[x];
        auto it = lower_bound(v.begin(), v.end(), i);
        if (it == v.end())
        {
            v.push_back(i);
        }
        else
        {
            v[it - v.begin()] = i;
        }
        if (x > 0)
        {
            auto it = lower_bound(v.begin(), v.end(), -(a[x - 1] - x));
            val[x] = (it - v.begin());
        }
        else
        {
            val[x] = v.size();
        }
        // cout << val[x] << " " << x + 1 << "\n";
    }
    ans = val[0];
    v.clear();
    for (int x = 0; x < n - 1; x++)
    {
        int i = a[x] - x;
        auto it = lower_bound(v.begin(), v.end(), i);
        if(it == v.end())
        {
            v.push_back(i);
        }
        else
        {
            v[it - v.begin()] = i;
        }
        ans = max(ans, (int)v.size() + val[x + 1]);
    }
    cout << ans << "\n";
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int x = 1; x <= t; x++)
    {
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...