This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |