Submission #649626

#TimeUsernameProblemLanguageResultExecution timeMemory
649626MEGalodonRabbit Carrot (LMIO19_triusis)C++14
100 / 100
30 ms4112 KiB
#include <bits/stdc++.h>
#define MAXN 200001
using namespace std;
int h[MAXN];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int N, M;
    cin>>N>>M;
    h[0] = 0;
    for( int i{1} ; i <= N ; ++i ){ cin>>h[i]; h[i] -= M*i; h[i] *= -1; }
    vector<int> LIS;
    LIS.push_back(0);
    //for( int i{0} ; i <= N ; ++i ) cout<<h[i]<<" "; cout<<'\n';
    for( int i{1} ; i <= N ; ++i ){
        if( h[i] >= LIS.back() ) LIS.push_back(h[i]);
        else{
            if( h[i] < 0 ) continue; //0 can never be replaced, it must be present in the LIS
            int p = upper_bound(LIS.begin(), LIS.end(), h[i])-LIS.begin();
            LIS[p] = h[i];
        }
    }
    cout<<N-LIS.size()+1<<'\n';
    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...