이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# 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... |