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;
#define ioss ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
int n, x;
int arr[200004], dp[200004];
signed main() {
ioss;
cin >> n >> x;
for(int i = 0; i < n; i++) cin >> arr[i];
if(x == 0) {
vector<int> tmp;
for(int i = 0; i < n; i++) {
if(i == 0) {
dp[i] = 1;
tmp.pb(arr[i]);
continue;
}
if(arr[i] > tmp.back()) dp[i] = dp[i-1]+1, tmp.pb(arr[i]);
else {
int cur = lower_bound(tmp.begin(), tmp.end(), arr[i])-tmp.begin();
tmp[cur] = arr[i];
dp[i] = dp[i-1];
// for(auto x : tmp) cout << x << " ";
// cout << endl;
}
// cout << " :: " << arr[i] << " " << tmp.back() << " " << dp[i] << endl;
}
cout << dp[n-1] << endl;
return 0;
}
vector<pii> range;
for(int j = 0; j < n; j++) {
for(int k = j; k < n; k++) {
range.pb({j, k});
}
}
int ans = 0;
for(auto [l, r] : range) {
// cout << l << " " << r << endl;
for(int k = -x; k <= x; k++) {
vector<int> tmp;
for(int i = 0; i < n; i++) dp[i] = 0;
for(int i = 0; i < n; i++) {
if(i == 0) {
dp[i] = 1;
tmp.pb(arr[i]);
continue;
}
if(i >= l && i <= r) arr[i] += k;
if(arr[i] > tmp.back()) dp[i] = dp[i-1]+1, tmp.pb(arr[i]);
else {
int cur = lower_bound(tmp.begin(), tmp.end(), arr[i])-tmp.begin();
tmp[cur] = arr[i];
dp[i] = dp[i-1];
// for(auto x : tmp) cout << x << " ";
// cout << endl;
}
// cout << " :: " << arr[i] << " " << tmp.back() << " " << dp[i] << endl;
if(i >= l && i <= r) arr[i] -= k;
ans = max(ans, dp[n-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... |