#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;
REP(i,1,n){
auto it2=lower_bound(b.begin(),b.end(),a[i]+m);
p[i]=it2-b.begin()-1;
auto it=upper_bound(b.begin(),b.end(),a[i]);
if(it==b.end()){
b.PB(a[i]);
continue;
}
int pos=it-b.begin();
pos--;
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,0,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();
pos--;
b[pos]=a[i];
ans=max(ans,p[i]+k);
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
46 ms |
5468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
1628 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
40 ms |
2876 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |