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;
long long dude(vector<long long>& haha, long long x) {
long long l = 0,r = haha.size()-1;
while(l < r) {
long long m = (l+r+1)/2;
if(haha[m] < x) {
l = m;
}
else {
r = m-1;
}
}
return l;
}
vector<int> br(200001);
void calc(vector<int> haha) {
reverse(haha.begin(),haha.end());
for(int i = 0; i < haha.size(); i++) {
haha[i] = INT_MAX-haha[i];
}
vector<long long> bruh(haha.size()+1,INT_MAX);
bruh[0] = 0;
for(int i = 0; i < haha.size(); i++) {
int a = haha[i];
int c = dude(bruh,a);
bruh[c+1] = a;
br[haha.size()-i-1] = c+1;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,x,ans = 0;
cin >> n >> x;
vector<int> haha(n);
for(int i = 0; i < n; i++) {
cin >> haha[i];
}
calc(haha);
vector<long long> bruh(n+1,INT_MAX);
bruh[0] = 0;
for(int i = 0; i < n; i++) {
int a = haha[i];
int c = dude(bruh,a+x);
ans = max(ans,c+br[i]);
c = dude(bruh,a);
ans = max(ans,c+1);
bruh[c+1] = a;
}
cout << ans;
return 0;
}
Compilation message (stderr)
glo.cpp: In function 'void calc(std::vector<int>)':
glo.cpp:22:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for(int i = 0; i < haha.size(); i++) {
| ~~^~~~~~~~~~~~~
glo.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int i = 0; i < haha.size(); 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... |