/*
File created on 06/19/2021 at 18:39:52.
Link to problem: https://oj.uz/problem/view/CEOI18_glo
Description:
Time complexity: O()
Space complexity: O()
Status: DEV
Copyright: Ⓒ 2021 Francois Vogel
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define ins insert
#define cls clear
#define int ll
#define ll long long
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int inf = 1e18;
signed main() {
cin.tie(0);
// ios_base::sync_with_stdio(0);
int n, x;
cin >> n >> x;
int b [n];
for (int i = 0; i < n; i++) cin >> b[i];
vector<int> dp(n, inf);
int mxv = 0;
int lp [n];
for (int i = 0; i < n; i++) {
int j = lower_bound(dp.begin(), dp.end(), b[i])-dp.begin();
lp[i] = j+1;
mxv = max(mxv, lp[i]);
dp[j] = b[i];
}
for (int i = 0; i < n; i++) b[i] *= -1;
dp = vector<int>(n, inf);
for (int i = n-1; i >= 0; i--) {
int j = lower_bound(dp.begin(), dp.end(), b[i])-dp.begin();
dp[j] = b[i];
int useful = lower_bound(dp.begin(), dp.end(), b[i]+x)-dp.begin();
mxv = max(mxv, lp[j]+useful);
}
cout << mxv;
int d = 0;
d++;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
129 ms |
8360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
32 ms |
2320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
56 ms |
4356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |