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>
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
signed main()
{
int n, x;
cin >> n >> x;
vector<int>t(n);
rep(i,n) cin>>t[i];
vector<int>c;
vector<int>right(n);
for(int i = n-1; i >=0; i--)
{
int r = 1e10 - t[i];
if(!c.size()||r>c[c.size()-1]) c.push_back(r);
else *(lower_bound(c.begin(), c.end(), r)) = r;
right[i] = c.size();
}
c = vector<int>(n, 1e17);
int maxx = 0;
rep(i,n)
{
auto it = lower_bound(c.begin(), c.end(), t[i] - x);
int off = it - c.begin();
maxx=max(maxx, right[i] + (lower_bound(c.begin(), c.end(), t[i] - x) - c.begin()));
*(lower_bound(c.begin(), c.end(), t[i]-x)) = t[i] - x;
}
cout<<maxx<<"\n";
}
Compilation message (stderr)
glo.cpp: In function 'int main()':
glo.cpp:30:13: warning: unused variable 'off' [-Wunused-variable]
30 | int off = it - c.begin();
| ^~~
# | 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... |