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>
typedef long long ll;
#define pb push_back
#define MS(x,y) memset((x),(y),sizeof((x)))
#define MN 1000000007
using namespace std;
int main()
{
#if LOCAL_DEBUG
fstream cin("in.txt");
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,x;
cin>>n>>x;
int niza[n];
for (int i = 0; i<n; i++) cin>>niza[i];
int dp[n], lisPref[n];
for (int i = 0; i<n; i++) dp[i] = INT_MAX/2;
int res = 0;
for (int i = 0; i<n; i++) {
auto sled = lower_bound(dp,dp+n,niza[i]);
int j = sled-dp;
dp[j] = niza[i];
lisPref[i] = j+1;
res = max(res,lisPref[i]);
}
for (int i = 0; i<n; i++) dp[i] = INT_MAX/2;
for (int i = n-1; i>=0; i--) {
auto prev = lower_bound(dp,dp+n,-niza[i]+x);
int j = prev-dp;
res = max(res,lisPref[i]+j);
auto ide = lower_bound(dp,dp+n,-niza[i]);
int idePos = ide-dp;
dp[idePos] = -niza[i];
}
cout<<res<<endl;
return 0;
}
# | 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... |