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 <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
ll m;
cin >> n >> m;
vector<ll> h(n + 1);
for (int i = 1; i <= n; i++) cin >> h[i];
vector<pair<ll, ll>> bc(0);
for (int i = 1; i <= n; i++) bc.push_back({ m * i - h[i], m * i + h[i] });
sort(bc.begin(), bc.end());
vector<ll> lis(1, 0);
for (pair<ll, ll> cbc : bc) if (cbc.first > -1)
{
if (cbc.second >= lis.back()) lis.push_back(cbc.second);
else
{
int l = upper_bound(lis.begin(), lis.end(), cbc.second) - lis.begin();
lis[l] = cbc.second;
}
}
cout << n + 1 - lis.size();
}
# | 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... |