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);
	vector<ll> lis(1, 0);
	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());
	for (pair<ll, ll> cbc : bc) if (cbc.first > -1)
	{
		if (cbc.second >= lis.back()) lis.push_back(cbc.second);
		else
		{
			int l = 0, r = lis.size() - 1;
			while (l < r)
			{
				int mid = l + (r - l) / 2;
				if (lis[mid] > cbc.second) r = mid;
				else l = mid + 1;
			}
			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... |