# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
395822 | Qw3rTy | Global Warming (CEOI18_glo) | C++11 | 27 ms | 2416 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 INF 1e9+5
#define pb push_back
using namespace std;
const int maxN = 1e5+5;
int a[maxN];
int f[maxN]; //length of LIS that ends on a[i]
int g[maxN]; //Length of longest decreasing subsequence that ends at a[i]
int N,d;
bool cmp(const int &a, const int &b){return a > b;}
void testIO(){
freopen("../test.in","r",stdin);
return;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
//testIO();
cin >> N >> d;
for(int i = 1; i <= N; ++i)cin >> a[i];
//Calculate f
f[0] = 0;
vector<int> dp;
for(int i = 1; i <= N; ++i){
int pos = lower_bound(dp.begin(),dp.end(),a[i]) - dp.begin();
if(pos == dp.size())
dp.pb(a[i]);
else dp[pos] = a[i];
f[i] = pos + 1;
}
//Calculate g
g[N+1] = 0;
dp.clear();
for(int i = N; i >= 1; --i){
int pos = lower_bound(dp.begin(),dp.end(),a[i],cmp) - dp.begin();
if(pos == dp.size())
dp.pb(a[i]);
else dp[pos] = a[i];
g[i] = pos + 1;
}
//Calculate answer
int res = 0;
for(int i = 0; i <= N; ++i){
if(a[i] - d < a[i+1]){
res = max(res, f[i] + g[i+1]);
}
}
cout << res << '\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... |