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 ans=0;
for(int j=1; j<=n; j++) b[j]=a[j];
for(int l=1; l<=n; l++) {
for(int r=l; r<=n; r++) {
for(int s=(-1)*x; s<=x; s+=(2*x)) {
mem_set();
for(int j=l; j<=r; 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=l; j<=r; 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... |