# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
716599 | nonono | Global Warming (CEOI18_glo) | C++17 | 119 ms | 4220 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"
#define SZ(x) (int)(x.size())
using namespace std;
const int mxN = 2e5 + 10;
int n, x, a[mxN];
int dp[mxN];
signed main(){
#define file "test"
if(fopen(file".inp", "r")){
freopen(file".inp", "r", stdin);
freopen(file".out", "w", stdout);
}
ios_base::sync_with_stdio();
cin.tie(); cout.tie();
cin >> n >> x;
for(int i = 1; i <= n; i ++){
cin >> a[i];
}
vector<int> f;
for(int i = 1; i <= n; i ++){
int pos = lower_bound(f.begin(), f.end(), a[i]) - f.begin();
if(pos == SZ(f)) f.push_back(a[i]);
f[pos] = a[i];
dp[i] = pos + 1;
}
f.clear();
int res = 0;
for(int i = n; i >= 1; i --){
int pos = lower_bound(f.begin(), f.end(), - a[i] + x) - f.begin();
res = max(res, dp[i] + pos);
pos = lower_bound(f.begin(), f.end(), - a[i]) - f.begin();
if(pos == SZ(f)) f.push_back(- a[i]);
f[pos] = - a[i];
}
cout << max(res, dp[n]) << "\n";
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... |