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 <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cctype>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cstdlib>
#include <bitset>
#include <deque>
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3fll
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 200005;
int a[maxn];
int n, x;
int f[maxn], g[maxn]; // f prefix, g suffix
int main() {
cin >> n >> x;
for (int i = 1; i <= n; i++) cin >> a[i];
vector<int> dp;
for (int i = 1; i <= n; i++) {
if (dp.empty() || a[i] > dp.back()) {
dp.push_back(a[i]);
f[i] = dp.size();
} else {
int pos = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
dp[pos] = a[i];
f[i] = pos + 1;
}
}
dp.clear();
for (int i = n; i >= 1; i--) {
int d = -(a[i] - x);
if (dp.empty() || d < dp.back()) {
dp.push_back(-a[i]);
g[i] = dp.size();
} else {
int pos = lower_bound(dp.begin(), dp.end(), d) - dp.begin();
dp[pos] = -a[i];
g[i] = pos + 1;
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
ans = max(ans, f[i] + g[i]);
}
cout << ans << 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |