Submission #940006

#TimeUsernameProblemLanguageResultExecution timeMemory
940006vjudge1Global Warming (CEOI18_glo)C++17
100 / 100
49 ms7260 KiB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, x; cin >> n >> x;
    vector <int> a(n);
    for ( auto &u: a ) cin >> u;
    const int inf = 1e12;
    vector <int> p(n + 1, -inf), r(n);
    for ( int i = n - 1; i >= 0; i-- ){
        int it = upper_bound(all(p), a[i]) - p.begin() - 1;
        p[it] = a[i];
        if ( i > 0 ){
            r[i - 1] = p.end() - upper_bound(all(p), a[i - 1] - x);
        }
    }
    int opt = p.end() - upper_bound(all(p), -inf + 1);
    p.assign(n + 1, inf);
    for ( int i = 0; i + 1 < n; i++ ){
        int it = lower_bound(all(p), a[i]) - p.begin();
        p[it] = a[i];
        chmax(opt, r[i] + it + 1);
    }
    cout << opt;

    cout << '\n';
}
#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...