Submission #483423

#TimeUsernameProblemLanguageResultExecution timeMemory
483423benkGlobal Warming (CEOI18_glo)C++17
100 / 100
47 ms2764 KiB
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define all(x)      x.begin(), x.end()
#define pb          push_back
#define sz(x)       (int)(x.size())
#define ll          long long
#define fi          first
#define se          second
#define lbd         lower_bound
#define ubd         upper_bound

template <typename T>
using ordered_set = tree<T, null_type,
      less<T>, rb_tree_tag,
      tree_order_statistics_node_update>;

const int MOD = 1e9 + 7;
const double eps = 1e-10;
const long long INF = 1e18;
const int N = 2e5 + 10;


void solve() {
	int n, x;
	cin >> n >> x;
	vector<int> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	vector<int> lds(n), dp;
	for (int i = n - 1; i >= 0; i--) {
		auto it = lbd(all(dp), -v[i] + x) - dp.begin();
		lds[i] = it + 1;
		it = lbd(all(dp), -v[i]) - dp.begin();
		if (it == sz(dp)) dp.pb(-v[i]);
		else dp[it] = -v[i];
	}
	dp = vector<int>();
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int it = lbd(all(dp), v[i]) - dp.begin();
		if (it == sz(dp)) dp.pb(v[i]);
		else dp[it] = v[i];
		ans = max(ans, it + lds[i]);
	}
	cout << ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int tt = 1;
	//cin >> tt;
	while (tt--) {
		solve();
		cout << '\n';
	}
	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...