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;
const long long Nmax = 2e5 + 5;
long long n, a[Nmax], m, b[Nmax], bit[Nmax];
void update(long long x, long long val)
{
for (; x < Nmax; x += x & -x)
{
bit[x] = max(bit[x], val);
}
}
long long gett(long long x)
{
long long res = 0;
for (; x > 0; x -= x & -x)
{
res = max(res, bit[x]);
}
return res;
}
int main()
{
cin >> n >> m;
for (long long i = 1; i <= n; ++i)
{
cin >> a[i];
}
long long nb = 0;
vector <long long> q;
for (long long i = 1; i <= n; ++i)
{
if (a[i] > m * i) continue;
b[++nb] = i * m - a[i];
q.push_back(b[nb]);
}
sort(q.begin(), q.end());
for (long long i = 1; i <= nb; ++i)
{
b[i] = lower_bound(q.begin(), q.end(), b[i]) - q.begin() + 1;
}
long long res = 0;
for (long long i = 1; i <= nb; ++i)
{
long long t = gett(b[i]) + 1;
update(b[i], t);
res = max(res, t);
}
cout << n - res;
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... |