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 MAX_N 200005
using namespace std;
int n, m;
int poles[MAX_N];
vector<int> b;
int dp[MAX_N];
int lnds() {
for(int i = 0; i < n; i++) {
int x = (i + 1) * m - poles[i];
if(x >= 0) {
b.push_back(x);
}
}
// longest non-decreasing subsequence
// dp[i] - smallest element for which the subsequence of length i ends
for(int i = 1; i <= n; i++) {
dp[i] = INT_MAX;
}
dp[0] = INT_MIN;
for(auto iterb : b) {
int l = 1, r = n;
int ans = 1;
while(l <= r) {
int mid = l + (r - l) / 2;
if(dp[mid] > iterb) {
ans = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
dp[ans] = iterb;
}
for(int i = 1; i <= n; i++) {
if(dp[i] == INT_MAX) {
return i - 1;
}
}
return n;
}
int main() {
cin >> n >> m;
for(int i = 0; i < n; i++) {
cin >> poles[i];
}
cout << n - lnds();
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... |