This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
#define LL long long
LL N, X;
LL A[200005];
LL PR[200005];
LL dp[200005];
int main() {
cin >> N >> X;
for (int i = 1; i <= N; i++) {
cin >> A[i];
}
LL res = 0;
dp[1] = A[1];
LL E = 2;
for (int i = 2; i <= N; i++) {
int ind = lower_bound(dp+1,dp+E,A[i])-dp;
PR[i]=ind;
res = max(res,PR[i]);
dp[ind] = A[i];
if (ind==E) {
E++;
}
}
dp[1]=-A[N];
E=2;
for (int i = N-1; i>=1; i--) {
int ind = lower_bound(dp+1,dp+E,X-A[i])-dp;
res = max(res,PR[i]+ind-1);
ind = lower_bound(dp+1,dp+E,-A[i])-dp;
dp[ind]=-A[i];
if (ind == E) {
E++;
}
}
cout << res << endl;
}
# | 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... |