이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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> dp1;
for (int i = 1; i <= n; i++) {
if (dp1.empty() || a[i] > dp1.back()) {
dp1.push_back(a[i]);
f[i] = dp1.size();
} else {
int pos = lower_bound(dp1.begin(), dp1.end(), a[i]) - dp1.begin();
dp1[pos] = a[i];
f[i] = pos + 1;
}
}
vector<int> dp2(n + 2, inf);
for (int i = n; i >= 1; i--) {
int pos1 = lower_bound(dp2.begin(), dp2.end(), -(a[i] - x)) - dp2.begin();
int pos2 = lower_bound(dp2.begin(), dp2.end(), -a[i]) - dp2.begin();
dp2[pos2] = -a[i];
g[i] = pos1;
}
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... |