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>
using namespace std;
typedef pair<int,int> pii;
const int MAXN=200005;
int MAX,a[MAXN],bit[MAXN];
map<int,int> mp;
int query(int x){
int ret=0;
for(int i=x;i>0;i-=(i&-i)){
ret=max(ret,bit[i]);
}
return ret;
}
void update(int x,int v){
for(int i=x;i<=MAX;i+=(i&(-i))){
bit[i]=max(bit[i],v);
}
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n,m;
cin >> n >> m;
for(int i=1;i<=n;i++){
cin >> a[i];
a[i]-=(i*m);
}
vector<pii> v;
for(int i=0;i<=n;i++){
if(a[i]>0)continue;
v.push_back({-a[i],i});
}
for(auto isi : v)mp[isi.first];
for(map<int,int>::iterator it=mp.begin();it!=mp.end();++it){
MAX++;
mp[it->first]=MAX;
}
int ans=0;
for(auto isi : v){
int dp=query(mp[isi.first])+1;
update(mp[isi.first],dp);
ans=max(ans,dp);
}
cout << n+1-ans << endl;
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... |