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;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define int long long
const int maxn = 1e5 + 5;
const ll INF = 1e18;
signed main(void){
fastio;
int n, x;
cin>>n>>x;
vector<int> a(n);
for(int i = 0; i < n; i++) cin>>a[i];
vector<int> fr(n), bk(n);
vector<int> len;
for(int i = 0; i < n; i++){
int id = lower_bound(len.begin(), len.end(), a[i]) - len.begin();
if(id == len.size()) len.pb(a[i]);
else len[id] = a[i];
fr[i] = id + 1;
}
for(int i = 0; i < n; i++) a[i] *= -1;
len.clear();
for(int i = n - 1; i >= 0; i--){
int cur = lower_bound(len.begin(), len.end(), a[i] + x) - len.begin();
bk[i] = cur + 1;
int id = lower_bound(len.begin(), len.end(), a[i]) - len.begin();
if(id == len.size()) len.pb(a[i]);
else len[id] = a[i];
}
int ans = 0;
for(int i = 0; i < n; i++) ans = max(ans, fr[i] + bk[i] - 1);
cout<<ans<<"\n";
}
Compilation message (stderr)
glo.cpp: In function 'int main()':
glo.cpp:24:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | if(id == len.size()) len.pb(a[i]);
| ~~~^~~~~~~~~~~~~
glo.cpp:34:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | if(id == len.size()) len.pb(a[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... |