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>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define mp make_pair
#define F first
#define S second
constexpr int maxn = 2e5 + 10;
int n, x;
int t[maxn];
int l[maxn];
vector<int> dp;
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
cin >> n >> x;
for (int i = 0; i < n; i++) cin >> t[i];
vector<int> dp(n, INT_MAX);
int lis = 0;
for (int i = 0; i < n; i++) {
int j = lower_bound(dp.begin(), dp.end(), t[i]) - dp.begin();
dp[j] = t[i];
l[i] = j + 1;
lis = max(lis, l[i]);
}
vector<int> dp2(n, INT_MAX);
for (int i = n - 1; i >= 0; i--) {
int p = lower_bound(dp2.begin(), dp2.end(), x - t[i]) - dp2.begin();
lis = max(lis, l[i] + p);
int ins = lower_bound(dp2.begin(), dp2.end(), -t[i]) - dp2.begin();
dp2[ins] = -t[i];
}
cout << lis << '\n';
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |