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 long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll n, m;
cin >> n >> m;
n++;
vector<ll> arr(n);
for (int i = 0; i < n; i++) {
if (i == 0) arr[i] = 0;
else {
ll val;
cin >> val;
arr[i] = val;
}
}
// find the length of the longest decreasing subsequence
vector<ll> dp(n, -1);
ll lis = 0;
for (ll i = 0; i < n; i++) {
ll start = 0;
ll end = lis;
while (start < end) {
ll mid = start+(end-start)/2;
if (arr[dp[mid]] + m >= arr[i]) start = mid + 1;
else end = mid;
}
if (start != 0 || i == 0) {
dp[start] = i;
if (start == lis) ++lis;
}
}
cout << n - lis;
}
# | 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... |