//UPDATERA ARRAY STORLEKEN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e15;
const ll MAXN=200006;//UPDATERA ARRAY STORLEKEN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ll n,lst[MAXN],ans,m,dp[MAXN],cnt;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
for(int i=1;i<=n;i++){
ll a;
cin>>a;
lst[i]=m*i-a;
}
//longest nondecreasing subsequence
for(int i=1;i<=n;i++){
if(lst[i]<0) continue;
ll pos=upper_bound (dp+1,dp+cnt+1,lst[i])-dp;//1 indexing
if(pos==cnt+1||lst[i]==dp[cnt]){//equal last one
dp[++cnt]=lst[i];
}else{
dp[pos]=lst[i];//use upperbound to change,yes can optimize next one
}
}
cout<<n-cnt<<'\n';
}
| # | 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... |