이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// - Only when necessary :d
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fileopen(a, b) freopen(((string)a + ".inp").c_str(), "r", stdin); freopen(((string)b + ".out").c_str(), "w", stdout);
#define ll long long
// #define int long long
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll mod = 1e9 + 7;
const ll inf = 1e9 + 7;
const double eps = 1e-9;
int n, x;
int a[200005];
int dp[200005], pmx[200005];
int ans = -inf;
void solve() {
cin >> n >> x;
for (int i = 1; i <= n; ++i) cin >> a[i];
dp[0] = -inf;
for (int i = 1; i <= n; ++i) dp[i] = inf;
for (int i = 1; i <= n; ++i) {
int idx = lower_bound(dp + 1, dp + n + 1, a[i]) - dp;
dp[idx] = a[i];
pmx[i] = idx;
}
dp[0] = -inf;
for (int i = 1; i <= n; ++i) dp[i] = inf;
for (int i = n; i >= 1; --i) {
int idx = lower_bound(dp + 1, dp + n + 1, -a[i] + x) - dp;
ans = max(ans, pmx[i] + idx - 1);
if (pmx[i] + idx - 1 == 5) {
// cout << "i : " << i << "\n";
// cout << "pmx : " << pmx[i] << "\n";
// cout << "idx : " << idx << "\n\n";
}
idx = lower_bound(dp + 1, dp + n + 1, -a[i]) - dp;
dp[idx] = -a[i];
}
cout << ans;
}
signed main() {
#ifdef khangorz
fileopen("input", "output");
#endif
#ifndef khangorz
// fileopen("LAH", "LAH");
#endif
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
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... |