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 int long long
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()
template<class S, class T>
bool chmin(S &a, const T &b) {
return a > b ? (a = b) == b : false;
}
template<class S, class T>
bool chmax(S &a, const T &b) {
return a < b ? (a = b) == b : false;
}
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, x; cin >> n >> x;
int a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
if (x == 0) {
vector<int> dp;
for (auto i : a) {
auto it = lower_bound(all(dp), i);
if (it == dp.end()) dp.push_back(i);
else dp[it - dp.begin()] = i;
}
cout << size(dp);
} else {
int res = 0;
for (int i = 0; i < n; ++i) {
a[i] += x;
}
for (int i = 0; i < n; ++i) {
a[i] -= x;
vector<int> dp;
for (auto i : a) {
auto it = lower_bound(all(dp), i);
if (it == dp.end()) dp.push_back(i);
else dp[it - dp.begin()] = i;
}
chmax(res, size(dp));
}
for (int i = 0; i < n; ++i) {
a[i] -= x;
}
for (int i = n - 1; i >= 0; --i) {
a[i] += x;
vector<int> dp;
for (auto i : a) {
auto it = lower_bound(all(dp), i);
if (it == dp.end()) dp.push_back(i);
else dp[it - dp.begin()] = i;
}
chmax(res, size(dp));
}
cout << res;
}
}
# | 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... |