#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define pb push_back
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n, m; cin >> n >> m;
vector<int> a(n);
for(int i=0; i<n; i++) cin >> a[i];
reverse(all(a));
for(int i=0; i<n; i++){
a[i] += i*m;
}
vector<int> L;
for(auto x: a){
int j = upper_bound(all(L), x) - begin(L);
if(j == sz(L)) L.pb(x);
else L[j] = x;
}
int j = upper_bound(all(L), n*m) - begin(L);
int ans = n-j;
cout << ans;
}
# | 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... |