Submission #650495

#TimeUsernameProblemLanguageResultExecution timeMemory
650495fatemetmhrGlobal Warming (CEOI18_glo)C++17
100 / 100
63 ms6200 KiB
//  ~Be name khoda~  //

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb       push_back
#define mp       make_pair
#define all(x)   x.begin(), x.end()
#define fi       first
#define se       second
#define cl       clear
#define endll    '\n'

const int maxn  =  1e6   + 10;
const int maxn5 =  5e5   + 10;
const int maxnt =  1.2e6 + 10;
const int maxn3 =  1e3   + 10;
const int mod   =  1e9   +  7;
const ll  inf   =  1e9;

ll dp[maxn5], a[maxn5];
int lastof[maxn5];

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	int n, x; cin >> n >> x;
	fill(dp, dp + n + 10, inf);
	int ans = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		int p = lower_bound(dp + 1, dp + n + 5, a[i]) - dp;
		lastof[i] = p;
		dp[p] = a[i];
		ans = max(ans, p);
	}
	fill(dp, dp + n + 10, inf);
	for(int i = n - 1; i >= 0; i--){
		int p = lower_bound(dp + 1, dp + n + 5, -1 * a[i] + x) - dp;
		ans = max(ans, p + lastof[i] - 1);
		p = lower_bound(dp + 1, dp + n + 5, -1 * a[i]) - dp;
		dp[p] = -1 * a[i];
	}
	cout << ans << endl;
}
#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...