/*
* AUTHOR : lo0ker
* Problem : Global warming
* source :
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
const int MOD = 1e9+7;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
ll x;
cin >> n >> x;
vector<ll> v(n);
vector<ll> revv(n);
for(int i = 0; i < n; i++){
cin >> v[i];
revv[i] = 0-v[i];
}
vi pre(n, 0);
vi suff(n, 0);
vector<ll> temp;
temp.push_back(v[0]);
pre[0] = 1;
for(int i = 1; i < n; i++){
if(v[i] > temp.back()){
temp.push_back(v[i]);
}
else{
int idx = lower_bound(temp.begin(), temp.end(), v[i]) - temp.begin();
temp[idx] = v[i];
}
pre[i] = temp.size();
}
temp.clear();
temp.push_back(revv[n-1]);
suff[n-1] = 1;
for(int i = n-2; i >= 0; i--){
if(revv[i] > temp.back()){
temp.push_back(revv[i]);
}
else{
int idx = lower_bound(temp.begin(), temp.end(), revv[i]) - temp.begin();
temp[idx] = revv[i];
}
suff[i] = temp.size();
}
int ans = pre[n-1];
for(int i = 0; i < n-1; i++){
if(v[i] >= v[i+1] && v[i] - v[i+1] < x){
ans = max(ans, pre[i] + suff[i+1]);
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
4944 KB |
Output is correct |
2 |
Correct |
34 ms |
5128 KB |
Output is correct |
3 |
Correct |
42 ms |
4944 KB |
Output is correct |
4 |
Correct |
41 ms |
5124 KB |
Output is correct |
5 |
Correct |
17 ms |
6272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1616 KB |
Output is correct |
2 |
Correct |
9 ms |
1616 KB |
Output is correct |
3 |
Correct |
9 ms |
1616 KB |
Output is correct |
4 |
Incorrect |
5 ms |
1872 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
2640 KB |
Output is correct |
2 |
Correct |
17 ms |
2640 KB |
Output is correct |
3 |
Correct |
36 ms |
5128 KB |
Output is correct |
4 |
Correct |
17 ms |
6096 KB |
Output is correct |
5 |
Correct |
9 ms |
3452 KB |
Output is correct |
6 |
Correct |
15 ms |
6264 KB |
Output is correct |
7 |
Correct |
18 ms |
5896 KB |
Output is correct |
8 |
Correct |
14 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |