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 ll long long
#define endl "\n"
#define FILE "DAYDEP"
using namespace std;
int n,x;
ll a[200005],dp[200005];
void sub2()
{
for(int i=1;i<=n;i++) dp[i]=10000000000;
int ans=0;
for(int i=1;i<=n;i++){
int k=lower_bound(dp+1,dp+n+1,a[i])-dp;
dp[k]=a[i];
ans=max(ans,k);
}
cout<<ans;
}
void solve()
{
int ans=0;
for(int i=1;i<n;i++){
int cnt=1;
ll mx=-1e9;
int d=0;
for(int j=i+1;j<=n;j++){
if(a[j]>a[i]){
cnt++;
mx=max(mx,a[i]);
}
else{
int dem=0;
if(a[j]+x<=mx) continue;
for(int k=j+1;k<=n;k++){
if(a[k]+x>mx) mx=a[k],dem++;
}
mx=a[j];
d=max(d,dem);
}
}
cnt+=d;
ans=max(d,ans);
}
cout<<ans;
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//freopen(FILE".inp","r",stdin);
//freopen(FILE".out","w",stdout);
cin>>n>>x;
for(int i=1;i<=n;i++) cin>>a[i];
if(x==0) sub2();
else solve();
}
# | 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... |