#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
typedef tuple<int,int,int> tii;
typedef vector<ll> li;
typedef vector<li> lii;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define LSOne(s) ((s)&(-s))
ll INF=1e18+10;
int inf=1e9+10;
ll M=1e9+7;
int main() {
// ios::sync_with_stdio(0);
// cin.tie(0);
int n,m;cin>>n>>m;
vi a(n),b,p(n);
REP(i,0,n)cin>>a[i];
REP(i,0,n)a[i]=-a[i];
b.PB(a[0]);p[0]=0;
reverse(a.begin(),a.end());
REP(i,1,n){
auto it2=lower_bound(b.begin(),b.end(),a[i]+m);
p[i]=it2-b.begin();
auto it=upper_bound(b.begin(),b.end(),a[i]);
if(it==b.end()){
b.PB(a[i]);
continue;
}
int pos=it-b.begin();
b[pos]=a[i];
}
reverse(a.begin(),a.end());
REP(i,0,n)a[i]=-a[i];
reverse(p.begin(),p.end());
b.clear();
b.PB(a[0]);
int k=b.size();
int ans=k+p[0];
REP(i,1,n){
auto it=upper_bound(b.begin(),b.end(),a[i]);
if(it==b.end()){
b.PB(a[i]);k++;
ans=max(ans,p[i]+k);
continue;
}
int pos=it-b.begin();
b[pos]=a[i];
ans=max(ans,p[i]+k);
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
1884 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
1116 KB |
Output is correct |
2 |
Correct |
28 ms |
2108 KB |
Output is correct |
3 |
Correct |
87 ms |
3892 KB |
Output is correct |
4 |
Incorrect |
62 ms |
3788 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |