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 int long long
# define vi vector<int>
# define pb push_back
# define pii pair<int, int>
# define fi first
# define se second
# define endl '\n'
# define jess ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, x, a[200005], b[200005], memo[1005][1005];
void mem_set() {
for(int i=0; i<=n+1; i++) {
for(int j=0; j<=n+1; j++) memo[i][j]=-1;
}
}
int dp(int idx, int last) {
if(idx>n) return 0;
if(memo[idx][last]!=-1) return memo[idx][last];
int best=dp(idx+1, last);
if(b[idx]>b[last]) {
best=max(best, dp(idx+1, idx)+1);
}
return memo[idx][last]=best;
}
void solve() {
cin >> n >> x;
for(int i=1; i<=n; i++) {
cin >> a[i];
}
int last=a[1], start=1, end=1;
vector<pii> v;
for(int i=2; i<=n; i++) {
if(a[i]>last) {
last=a[i];
end++;
} else {
v.pb({start, end});
start=i;
last=a[i];
end=i;
}
}
v.pb({start, n});
int ans=0;
for(int j=1; j<=n; j++) b[j]=a[j];
for(pii i : v) {
for(int s=(-1)*x; s<=x; s++) {
mem_set();
for(int j=i.fi; j<=i.se; j++) {
b[j]+=s;
}
b[0]=0;
// cout << "plus " << s << endl;
// cout << "dp " << dp(1, 0) << endl;
ans=max(ans, dp(1, 0));
for(int j=i.fi; j<=i.se; j++) b[j]-=s;
}
}
cout << ans << endl;
}
signed main() {
jess;
solve();
}
# | 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... |