Submission #1255305

#TimeUsernameProblemLanguageResultExecution timeMemory
1255305muhammadali_2009Rabbit Carrot (LMIO19_triusis)C++20
100 / 100
18 ms6588 KiB
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+     //

#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define ll long long
#define int long long
#define all(x) x.begin(), x.end()
#define seea(x) for(int i = 0; i < x; i++)
#define pb push_back

using namespace std;

int lnis(const vector<int>& a){
    vector<int> dp;
    for(int x : a){
        auto it = upper_bound(dp.begin(), dp.end(), x, greater<int>());
        if(it == dp.end()) dp.push_back(x);
        else *it = x;
    }
    return (int)dp.size();
}

void solve(){
    int n, mx; cin >> n >> mx;
    vector<int> a(n);
    seea(n) cin >> a[i];

    vector<int> c;
    for(int i = 1; i <= n; ++i){
        if(i * mx >= a[i-1]){
            c.push_back(a[i-1] - i * mx);
        }
    }

    int keep = lnis(c);       
    cout << n - keep << endl; 
}

signed main(){
    fast;
    int t = 1;
    //cin >> t;
    while(t--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...