| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 863390 | Arthas | Global Warming (CEOI18_glo) | C++17 | 0 ms | 0 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
 
#define all(x) x.begin(),x.end();
 
int N = 3e5 + 10, INF = 2e9 + 10;
 
int n, x, a[N], l[N], ans;
vector <int> v(N, INF);
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> x;
  for (int i = 0; i < n; ++ i){
    cin >> a[i];
  }
  v[0] = -INF;
  for (int i = 0; i < n; ++ i){
    int p = lower_bound (all(v), a[i]) - v.begin();
    v[p] = a[i];
    l[i] = p;
    ans = max (ans, p);
  }
  for (int i = 0; i < n; ++ i){
    v[i] = INF;
  }
  v[0] = -INF;
  for (int i = n - 1; i >= 0; -- i){
    int p = lower_bound (all(v), -a[i] + x) - v.begin();
    ans = max (ans, l[i] + p - 1);
    p = lower_bound (all(v), -a[i]) - v.begin();
    v[p] = -a[i];
  }
  cout << ans;
  return 0;
}
