제출 #1113077

#제출 시각아이디문제언어결과실행 시간메모리
1113077raspyGlobal Warming (CEOI18_glo)C++17
100 / 100
57 ms8544 KiB
#include <bits/stdc++.h>
#include <iostream>
#include <set>
#include <map>

#define int long long
#define vi vector<int>
#define ii pair<int, int>
#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define P 31
#define mod 1'000'000'007
#define inf 1'000'000'000'000
#define pb push_back
#define str string
#define sz(x) (x).size()
#define vvi vector<vi>
#define fun function
#define oopt cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false);
#define file freopen("problemname.in", "r", stdin); freopen("pr.out", "w", stdout);
#define dbg(v) cout << "Line(" << __LINE__ << ") -> " << #v << " = " << (v) << endl;

using namespace std;
template <class T, int SZ> using arr = array<T, SZ>;

void solve()
{
	int n, x;
	cin >> n >> x;
	vi a(n);
	for (int&v:a)
		cin >> v;
	vi lis(n, inf);
	vi lds(n, inf);
	vi rhs(n);
	for (int i = n-1; i >= 0; i--)
	{
		a[i] = -a[i];
		int ix = lower_bound(all(lds), a[i])-lds.begin();
		lds[ix] = a[i];
		rhs[i] = ix+1;
		a[i] = -a[i];
		// cout << i << " " << rhs[i] << "\n";
	}
	int rez = 0;
	for (int i = 0; i < n; i++)
	{
		int ix = lower_bound(all(lis), a[i]+x)-lis.begin();
		// cout << i << " " << ix << " " << rhs[i] << "\n";
		rez = max(rez, ix+rhs[i]);
		ix = lower_bound(all(lis), a[i])-lis.begin();
		lis[ix] = a[i];
	}
	cout << rez << "\n";
}

signed main()
{
	oopt;
	int t = 1;
	// cin >> t;
	while (t--)
		solve();
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...