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;
int main() {
//days, max decrement
int n, x;
cin >> n >> x;
int days[n];
for (int i = 0; i < n; i++)
cin >> days[i];
int pref[n];
int suff[n];
int dp[n];
fill(dp, dp+n, 1000000007);
for (int i = 0; i < n; i++){
int pos = lower_bound(dp, dp+n, days[i])-dp;
dp[pos] = days[i];
pref[i] = pos+1;
}
fill(dp, dp+n, 1000000007);
for (int i = n-1; i >= 0; i--){
int pos = lower_bound(dp, dp+n, -(days[i]-x))-dp;
suff[i] = pos+1;
pos = lower_bound(dp, dp+n, -days[i])-dp;
dp[pos] = -days[i];
}
int ans = 0;
for (int i = 0; i < n; i++){
ans = max(ans, pref[i]+suff[i]-1);
}
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... |