# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
313939 | BeanZ | Global Warming (CEOI18_glo) | C++14 | 57 ms | 6512 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 2e5 + 5;
ll dp[N], a[N];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("A.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll n, x;
cin >> n >> x;
for (int i = 1; i <= n; i++) cin >> a[i];
vector<ll> val;
ll ans = 0;
for (int i = n; i >= 1; i--){
ll l = 0, h = val.size() - 1;
while (l <= h){
ll mid = (l + h) >> 1;
if (val[mid] > a[i]) l = mid + 1;
else h = mid - 1;
}
if (l == val.size()) val.push_back(a[i]);
else {
val[l] = max(val[l], a[i]);
}
dp[i] = l + 1;
ans = max(ans, dp[i]);
}
val.clear();
for (int i = 1; i <= n; i++){
ll l = 0, h = val.size() - 1;
while (l <= h){
ll mid = (l + h) >> 1;
if (val[mid] < a[i]) l = mid + 1;
else h = mid - 1;
}
if (l == val.size()) val.push_back(a[i]);
else {
val[l] = min(val[l], a[i]);
}
ans = max(ans, (ll)val.size());
if (i == n) continue;
l = 0, h = val.size() - 1;
while (l <= h){
ll mid = (l + h) >> 1;
if (val[mid] >= (a[i + 1] + x)){
h = mid - 1;
} else l = mid + 1;
}
ans = max(ans, h + 1 + dp[i + 1]);
}
cout << ans;
}
/*
*/
Compilation message (stderr)
# | 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... |