Submission #1199300

#TimeUsernameProblemLanguageResultExecution timeMemory
1199300iamhereforfunGlobal Warming (CEOI18_glo)C++20
100 / 100
37 ms2504 KiB
// IamHereForFun //

#include <bits/stdc++.h>

using namespace std;

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

const int N = 2e5 + 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 = 0; x < n; x++)
    {
        int i = a[x];
        auto it = lower_bound(v.begin(), v.end(), i);
        val[x] = it - v.begin() + 1;
        if (it == v.end())
        {
            v.push_back(i);
        }
        else
        {
            v[it - v.begin()] = i;
        }
        ans = max(ans, val[x]);
    }
    v.clear();
    for (int x = n - 1; x >= 0; x--)
    {
        int i = -a[x];
        auto it = lower_bound(v.begin(), v.end(), -(a[x] - d));
        ans = max(ans, (int)(it - v.begin() + val[x]));
        {
            auto it = lower_bound(v.begin(), v.end(), i);
            if (it == v.end())
            {
                v.push_back(i);
            }
            else
            {
                v[it - v.begin()] = i;
            }
        }
    }
    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...