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 <iostream>
#include <algorithm>
#include <vector>
#include <climits>
using namespace std;
#define problemname "glo"
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define MOD (int)1e9+7
#define ll long long
#define ff first
#define ss second
bool ckmin(int& a, int b) {return a>b?a=b,true:false;}
bool ckmax(int& a, int b) {return a<b?a=b,true:false;}
int main () {
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen (problemname ".in", "r", stdin); freopen(problemname ".out", "w", stdout);
int n,x;cin>>n>>x;
vi a(n); for(auto& x: a) cin>>x;
vi left;
vi dp;
int ans = 0;
for(auto lmao:a) {
int pos = lower_bound(dp.begin(), dp.end(), lmao) - dp.begin();
if(pos == dp.size()) {
dp.pb(x);
} else {
dp[pos]=lmao;
}
left.pb(pos);
ckmax(ans, left[left.size()-1]);
}
dp.clear();
vi right;
for(int i=n-1; i>=0; i--) {
a[i]=-a[i];
int pos = lower_bound(dp.begin(), dp.end(), a[i] + x) - dp.begin();
int ins = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
if(ins == dp.size()) {
dp.pb(a[i]);
} else {
dp[ins]=a[i];
}
right.pb(dp.size());
a[i]=-a[i];
ckmax(ans, left[i]+pos);
}
cout<<ans+1<<endl;
return 0;
}
Compilation message (stderr)
glo.cpp: In function 'int main()':
glo.cpp:29:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | if(pos == dp.size()) {
| ~~~~^~~~~~~~~~~~
glo.cpp:43:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | if(ins == dp.size()) {
| ~~~~^~~~~~~~~~~~
# | 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... |