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;
constexpr int NMAX = 2e5 + 5;
int N, M;
LL A[NMAX];
/*
j < i
j -> i
A[j] >= A[i]
*/
void Read () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> M;
for (int i = 1; i <= N; ++ i ) {
cin >> A[i];
A[i] -= (1LL * i * M);
}
}
int vf;
LL Best[NMAX];
int CautBinar (LL value) {
int st = 1, dr = vf;
int ans = 0;
while (st <= dr) {
int mij = (st + dr) / 2;
if (Best[mij] <= value) {
st = mij + 1;
ans = mij;
}
else dr = mij - 1;
}
return ans;
}
void Solve () {
for (int i = N; i >= 1; -- i ) {
int pos = CautBinar(A[i]) + 1;
if (pos > vf) {
++ vf;
Best[vf] = A[i];
}
Best[pos] = min(Best[pos], A[i]);
}
cout << N - CautBinar(0) << '\n';
}
int main () {
Read();
Solve();
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... |