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>
//#include "bits_stdc++.h"
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
int main()
{
ll n,x;
cin >> n >> x;
ll arr[n], right[n];
vector<ll> lis;
for (ll i=0; i<n; ++i) cin >> arr[i];
for (ll i=n-1; i>=0; --i)
{
ll ind = lb(lis.begin(), lis.end(), -arr[i])-lis.begin();
if (ind>=lis.size())
{
lis.pb(-arr[i]);
}
else
{
lis[ind] = -arr[i];
}
right[i] = ind;
}
ll ans = 0;
lis.resize(0);
for (ll i=0; i<n; ++i)
{
ll left = lb(lis.begin(), lis.end(), arr[i]+x) -lis.begin();
ans = max(ans, left + right[i] + 1);
ll ind = lb(lis.begin(), lis.end(), arr[i]) -lis.begin();
if (ind>=lis.size()) lis.pb(arr[i]);
else lis[ind] = arr[i];
}
cout << ans << endl;
return 0;
}
Compilation message (stderr)
glo.cpp: In function 'int main()':
glo.cpp:31:10: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | if (ind>=lis.size())
| ~~~^~~~~~~~~~~~
glo.cpp:48:10: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | if (ind>=lis.size()) lis.pb(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... |