#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x) cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define ull unsigned long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ld long double
#define nl endl
#define tb '\t'
#define sp ' '
#define sqr(x) (x)*(x)
#define arr3 array<ll, 3>
using namespace std;
const ll MX=200005, MOD=1000000007, BLOCK=160, INF=2e9+7, LG=62;
const ll INFF=1000000000000000007;
const ld ERR=1e-6, pi=3.14159265358979323846;
int N, K, A[MX], best[MX], ans;
vector<int> LIS;
int main(){
fastio;
cin >> N >> K;
for(int i=1; i<=N; i++){
cin >> A[i];
}
for(int i=1; i<=N; i++){
int tmp=A[i], idx;
if(LIS.empty() || LIS.back()<tmp){
idx=LIS.size();
LIS.pb(tmp);
}else{
idx=lower_bound(all(LIS), tmp)-LIS.begin();
LIS[idx]=tmp;
}
idx++;
best[i]=idx;
ans=max(ans, idx);
}
LIS.clear();
for(int i=N; i>0; i--){
int tmp=-A[i], idx;
if(LIS.empty() || LIS.back()<tmp){
idx=LIS.size();
}else{
idx=lower_bound(all(LIS), tmp)-LIS.begin();
}
ans=max(ans, best[i]+idx);
tmp=-A[i]-K;
if(LIS.empty() || LIS.back()<tmp){
idx=LIS.size();
LIS.pb(tmp);
}else{
idx=lower_bound(all(LIS), tmp)-LIS.begin();
LIS[idx]=tmp;
}
}
cout << ans << nl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
2656 KB |
Output is correct |
2 |
Correct |
50 ms |
2348 KB |
Output is correct |
3 |
Correct |
52 ms |
2280 KB |
Output is correct |
4 |
Correct |
57 ms |
2328 KB |
Output is correct |
5 |
Correct |
30 ms |
2788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1092 KB |
Output is correct |
2 |
Correct |
12 ms |
1060 KB |
Output is correct |
3 |
Correct |
12 ms |
1112 KB |
Output is correct |
4 |
Correct |
8 ms |
1240 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
6 ms |
1200 KB |
Output is correct |
7 |
Correct |
11 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1560 KB |
Output is correct |
2 |
Correct |
21 ms |
1504 KB |
Output is correct |
3 |
Correct |
46 ms |
2256 KB |
Output is correct |
4 |
Correct |
23 ms |
2856 KB |
Output is correct |
5 |
Correct |
15 ms |
1872 KB |
Output is correct |
6 |
Correct |
23 ms |
2704 KB |
Output is correct |
7 |
Correct |
23 ms |
2800 KB |
Output is correct |
8 |
Correct |
19 ms |
1460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
56 ms |
2656 KB |
Output is correct |
28 |
Correct |
50 ms |
2348 KB |
Output is correct |
29 |
Correct |
52 ms |
2280 KB |
Output is correct |
30 |
Correct |
57 ms |
2328 KB |
Output is correct |
31 |
Correct |
30 ms |
2788 KB |
Output is correct |
32 |
Correct |
12 ms |
1092 KB |
Output is correct |
33 |
Correct |
12 ms |
1060 KB |
Output is correct |
34 |
Correct |
12 ms |
1112 KB |
Output is correct |
35 |
Correct |
8 ms |
1240 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
6 ms |
1200 KB |
Output is correct |
38 |
Correct |
11 ms |
1108 KB |
Output is correct |
39 |
Correct |
22 ms |
1560 KB |
Output is correct |
40 |
Correct |
21 ms |
1504 KB |
Output is correct |
41 |
Correct |
46 ms |
2256 KB |
Output is correct |
42 |
Correct |
23 ms |
2856 KB |
Output is correct |
43 |
Correct |
15 ms |
1872 KB |
Output is correct |
44 |
Correct |
23 ms |
2704 KB |
Output is correct |
45 |
Correct |
23 ms |
2800 KB |
Output is correct |
46 |
Correct |
19 ms |
1460 KB |
Output is correct |
47 |
Correct |
24 ms |
2000 KB |
Output is correct |
48 |
Correct |
25 ms |
1980 KB |
Output is correct |
49 |
Correct |
50 ms |
3756 KB |
Output is correct |
50 |
Correct |
32 ms |
3504 KB |
Output is correct |
51 |
Correct |
27 ms |
2864 KB |
Output is correct |
52 |
Correct |
23 ms |
3568 KB |
Output is correct |
53 |
Correct |
21 ms |
3544 KB |
Output is correct |
54 |
Correct |
26 ms |
4284 KB |
Output is correct |
55 |
Correct |
40 ms |
3776 KB |
Output is correct |