#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <numeric>
#include <queue>
#include <assert.h>
#include <map>
#include <set>
#include <limits.h>
using namespace std;
#define ll long long
#define ld long double
const int MX = 10005;
const int LG = (int)log2(MX) + 2;
const int BLOCK = 105;
const ll mod = 1e9 + 7;
const ll inv2 = (mod + 1) / 2;
#define gc getchar//_unlocked //can't for window server
void cin(int &x){
char c = gc(); bool neg = false;
for(; c < '0'||'9' < c; c = gc())
if(c == '-') neg=true;
x = c - '0'; c = gc();
for(; '0' <= c && c <= '9'; c = gc())
x = (x << 1) + (x << 3) + (c - '0');
if(neg) x = -x;
}
int LIS(vector<int> v){
int sz = v.size();
vector<int> dp;
for(int i = 0; i < sz; i ++){
auto it = lower_bound(dp.begin(), dp.end(), v[i]);
if(it == dp.end()) dp.push_back(v[i]);
else dp[it - dp.begin()] = v[i];
}
return dp.size();
}
int n, x;
vector<int> v;
int main(){
cin(n); cin(x);
v.resize(n);
for(int i = 0; i < n; i ++)
cin(v[i]);
int ans = LIS(v);
vector<int> suff(n), dp; dp.assign(n, 0);
for(int i = n - 1; i >= 0; i --){
int it = upper_bound(dp.begin(), dp.end(), v[i]) - dp.begin() - 1;
dp[it] = v[i];
suff[i] = n - it;
}
dp.clear();
for(int i = 0; i < n; i ++){
int j = upper_bound(dp.begin(), dp.end(), v[i] + x - 1) - dp.begin();
ans = max(ans, j + suff[i]);
auto it = lower_bound(dp.begin(), dp.end(), v[i]);
if(it == dp.end()) dp.push_back(v[i]);
else dp[it - dp.begin()] = v[i];
}
printf("%d\n", ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
276 KB |
Output is correct |
17 |
Correct |
1 ms |
256 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
276 KB |
Output is correct |
17 |
Correct |
1 ms |
256 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
2652 KB |
Output is correct |
2 |
Correct |
64 ms |
2652 KB |
Output is correct |
3 |
Correct |
64 ms |
2652 KB |
Output is correct |
4 |
Correct |
63 ms |
2652 KB |
Output is correct |
5 |
Correct |
35 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
936 KB |
Output is correct |
2 |
Correct |
15 ms |
1320 KB |
Output is correct |
3 |
Correct |
17 ms |
1320 KB |
Output is correct |
4 |
Correct |
9 ms |
1260 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
9 ms |
1260 KB |
Output is correct |
7 |
Correct |
12 ms |
1468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
1508 KB |
Output is correct |
2 |
Correct |
27 ms |
1508 KB |
Output is correct |
3 |
Correct |
59 ms |
2652 KB |
Output is correct |
4 |
Correct |
33 ms |
2636 KB |
Output is correct |
5 |
Correct |
15 ms |
1516 KB |
Output is correct |
6 |
Correct |
30 ms |
2568 KB |
Output is correct |
7 |
Correct |
28 ms |
2568 KB |
Output is correct |
8 |
Correct |
21 ms |
1508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
276 KB |
Output is correct |
17 |
Correct |
1 ms |
256 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
64 ms |
2652 KB |
Output is correct |
28 |
Correct |
64 ms |
2652 KB |
Output is correct |
29 |
Correct |
64 ms |
2652 KB |
Output is correct |
30 |
Correct |
63 ms |
2652 KB |
Output is correct |
31 |
Correct |
35 ms |
2636 KB |
Output is correct |
32 |
Correct |
15 ms |
936 KB |
Output is correct |
33 |
Correct |
15 ms |
1320 KB |
Output is correct |
34 |
Correct |
17 ms |
1320 KB |
Output is correct |
35 |
Correct |
9 ms |
1260 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
9 ms |
1260 KB |
Output is correct |
38 |
Correct |
12 ms |
1468 KB |
Output is correct |
39 |
Correct |
28 ms |
1508 KB |
Output is correct |
40 |
Correct |
27 ms |
1508 KB |
Output is correct |
41 |
Correct |
59 ms |
2652 KB |
Output is correct |
42 |
Correct |
33 ms |
2636 KB |
Output is correct |
43 |
Correct |
15 ms |
1516 KB |
Output is correct |
44 |
Correct |
30 ms |
2568 KB |
Output is correct |
45 |
Correct |
28 ms |
2568 KB |
Output is correct |
46 |
Correct |
21 ms |
1508 KB |
Output is correct |
47 |
Correct |
32 ms |
2512 KB |
Output is correct |
48 |
Correct |
32 ms |
2404 KB |
Output is correct |
49 |
Correct |
70 ms |
4572 KB |
Output is correct |
50 |
Correct |
34 ms |
3788 KB |
Output is correct |
51 |
Correct |
28 ms |
3048 KB |
Output is correct |
52 |
Correct |
32 ms |
3916 KB |
Output is correct |
53 |
Correct |
32 ms |
3916 KB |
Output is correct |
54 |
Correct |
35 ms |
4684 KB |
Output is correct |
55 |
Correct |
50 ms |
4572 KB |
Output is correct |