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 s second
#define f first
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
// const int INF = 1e17;
const int N = 2*1e5 + 10;
int main() {
int n, x;
cin >> n >> x;
vi vals(n);
vi dp(n);
vi cur;
for (int i = 0; i < n; i++) {
cin >> vals[i];
auto ind = lower_bound(cur.begin(), cur.end(), vals[i]) - cur.begin();
if (ind == cur.size()) cur.pb(vals[i]);
else cur[ind] = vals[i];
// cout << i << ind << endl;
dp[i]=ind+1;
}
cur.erase(cur.begin(), cur.end());
int ans = 0;
for (int i = n-1; i >= 0; i--) {
int possible = lower_bound(cur.begin(), cur.end(), -vals[i] + x) - cur.begin();
// cout << i << possible << dp[i] << endl;
ans = max(ans, dp[i] + possible);
int ind = lower_bound(cur.begin(), cur.end(), -vals[i]) - cur.begin();
if (ind == cur.size()) cur.pb(-vals[i]);
else cur[ind]=-vals[i];
}
// cout << cur.size() << endl;
// assert(dp[n-1] == cur.size());
cout << ans << endl;
}
Compilation message (stderr)
glo.cpp: In function 'int main()':
glo.cpp:31:11: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | if (ind == cur.size()) cur.pb(vals[i]);
| ~~~~^~~~~~~~~~~~~
glo.cpp:45:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | if (ind == cur.size()) cur.pb(-vals[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... |