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;
int n, x, idx, arr[200010], pre[200010], ans;
vector<int> dp;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> x;
for(int i=1; i<=n; i++) {
cin >> arr[i];
idx = lower_bound(dp.begin(), dp.end(), arr[i]) - dp.begin();
if(idx == dp.size()) dp.push_back(arr[i]);
else dp[idx] = arr[i];
pre[i] = dp.size()+1;
}
ans = pre[n];
dp.clear();
for(int i=n-1; i>=0; i--) {
idx = lower_bound(dp.begin(), dp.end(), -arr[i]+x) - dp.begin();
ans = max(ans, pre[i] + idx);
idx = lower_bound(dp.begin(), dp.end(), -arr[i]) - dp.begin();
if(idx == dp.size()) dp.push_back(-arr[i]);
else dp[idx] = -arr[i];
}
cout << ans;
return 0;
}
Compilation message (stderr)
glo.cpp: In function 'int main()':
glo.cpp:14:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | if(idx == dp.size()) dp.push_back(arr[i]);
| ~~~~^~~~~~~~~~~~
glo.cpp:24:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | if(idx == dp.size()) dp.push_back(-arr[i]);
| ~~~~^~~~~~~~~~~~
# | 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... |