Submission #660538

#TimeUsernameProblemLanguageResultExecution timeMemory
660538hafoRabbit Carrot (LMIO19_triusis)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pa pair<int, int>
#define pall pair<ll, int>
#define fi first
#define se second
#define TASK "test"
#define all(x) x.begin(), x.end()
using namespace std;

template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;}

const int MOD = 1e9 + 7;
const int LOG = 20;
const int maxn = 2e5 + 7;
const int oo = 1e9 + 69;

int n, m, a[maxn], dp[maxn];

struct BIT {
    int bit[maxn];
    void init () {
        fill_n(bit, n + 1, -oo);
    }
    void update(int x, int val) {
        for(; x <= n; x += x & -x) maxi(bit[x], val);
    }

    int get(int x) {
        int ans = -oo;
        for(; x; x -= x & -x) maxi(ans, bit[x]);
        return ans;
    }
} bit;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //freopen(TASK".inp", "r", stdin);
    //freopen(TASK".out", "w", stdout);

    cin>>n>>m;
    vector<int> com;
    for(int i = 1; i <= n; i++) {
        cin>>a[i];
        dp[i] = -oo;
        com.pb(a[i]);
    }
    bit.init();

    int ans = 0;
    sort(all(com));
    for(int i = 1; i <= n; i++) {
        if(a[i] <= m) dp[i] = 1;
        int pos = lower_bound(all(com), a[i] - m) - com.begin() + 1;
        maxi(dp[i], bit.get(n - pos + 1) + 1);
        pos = lower_bound(all(com), a[i]) - com.begin() + 1;
        bit.update(n - pos + 1, dp[i]);
        maxi(ans, dp[i]);
    }
//    for(int i = 1; i <= n; i++) cout<<dp[i]<<" ";
    cout<<n - ans;
    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...