이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// ~Be name khoda~ //
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define cl clear
#define endll '\n'
const int maxn = 1e6 + 10;
const int maxn5 = 5e5 + 10;
const int maxnt = 1.2e6 + 10;
const int maxn3 = 1e3 + 10;
const int mod = 1e9 + 7;
const ll inf = 1e9;
ll dp[maxn5], a[maxn5];
int lastof[maxn5];
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n, x; cin >> n >> x;
fill(dp, dp + n + 10, inf);
int ans = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
int p = lower_bound(dp + 1, dp + n + 5, a[i]) - dp;
lastof[i] = p;
dp[p] = a[i];
ans = max(ans, p);
}
fill(dp, dp + n + 10, inf);
for(int i = n - 1; i >= 0; i--){
int p = lower_bound(dp + 1, dp + n + 5, -1 * a[i] + x) - dp;
ans = max(ans, p + lastof[i] - 1);
p = lower_bound(dp + 1, dp + n + 5, -1 * a[i]) - dp;
dp[p] = -1 * a[i];
}
cout << ans << endl;
}
# | 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... |