# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
314069 | tushar_2658 | Global Warming (CEOI18_glo) | C++14 | 72 ms | 3448 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.
#include "bits/stdc++.h"
using namespace std;
const int maxn = 200005;
int a[maxn], x;
int n;
int main(int argc, char const *argv[])
{
scanf("%d %d", &n, &x);
for(int i = 1; i <= n; ++i){
scanf("%d", &a[i]);
}
vector<int> dp(n + 1, 1e8);
dp[0] = -1e8;
vector<int> L(n + 1);
for(int i = 1; i <= n; ++i){
int idx = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
dp[idx] = a[i];
L[i] = idx;
}
vector<int> dp1(n + 1, 1e8);
dp1[0] = -1e8;
int ans = 0;
for(int i = n; i >= 1; --i){
int idx = lower_bound(dp1.begin(), dp1.end(), -a[i]) - dp1.begin();
int idx1 = lower_bound(dp1.begin(), dp1.end(), -a[i] + x) - dp1.begin();
dp1[idx] = -a[i];
ans = max(ans, L[i] + idx1 - 1);
}
cout << ans << endl;
return 0;
}
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... |