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<bits/stdc++.h>
#define int long long
#define pii pair<ll,ll>
#define fi first
#define se second
using namespace std;
using ll = long long;
using ldb = long double;
const int N = (int)5e5+2;
const int maxN = (int)5e5 + 5;
const int mod = 1e9 + 7;
const ll infty = 1e10;
void InputFile()
{
//freopen("scrivener.inp","r",stdin);
//freopen("scrivener.out","w",stdout);
//freopen("test.out","r",stdin);
}
void FastInput()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
/// prove that optimal answer can be achieved by decrease a prefix
int n,x;
int dp[2][maxN];
int e[2][maxN];
int t[maxN];
void Read()
{
cin >> n >> x;
for(int i = 1;i <= n;i++)
{
cin >> t[i];
}
fill(e[0] + 1,e[0] + n + 1,infty);
fill(e[1] + 1,e[1] + n + 1,infty);
for(int i = 1;i <= n;i++)
{
dp[1][i] = lower_bound(e[1] + 1,e[1] + n + 1,t[i]) - e[1];
e[1][dp[1][i]] = t[i];
dp[0][i] = lower_bound(e[0] + 1,e[0] + n + 1,t[i] - x) - e[0];
e[0][dp[0][i]] = t[i]-x;
e[1][dp[0][i]] = min(e[1][dp[0][i]],t[i]-x);
}
cout << *max_element(dp[1] + 1,dp[1] + n + 1);
}
void Solve()
{
}
void Debug()
{
//Main_sub();
//Naive();
}
int32_t main()
{
FastInput();
//InputFile();
//int sub_type;
//cin >> sub_type;
//Sieve();
int test;
//cin >> test;
test = 1;
while(test--)
//for(int prc = 1; prc <= test; prc++)
{
Read();
Solve();
//Debug();
}
}
/*
13 1
769 514 336 173 181 373 519 338 985 709 729 702 168
12 581
*/
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |