Submission #483340

#TimeUsernameProblemLanguageResultExecution timeMemory
483340BERNARB01Global Warming (CEOI18_glo)C++17
62 / 100
54 ms5024 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = (int) 2e5 + 9;
const int inf = (int) 2e9 + 9;

int n, x, a[N], dp[N], pd[N];
pair<int, int> suffix_lds_info[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 1;
  fill(dp, dp + n, inf);
  for (int i = n - 1; i >= 0; i--) {
    int j = lower_bound(dp, dp + n, -a[i]) - dp;
    dp[j] = -a[i];
    ans = max(ans, j + 1);
    suffix_lds_info[i] = {ans, x - dp[ans - 1]};
  }
  fill(dp, dp + n, inf);
  for (int i = 0; i < n - 1; i++) {
    int j = lower_bound(dp, dp + n, a[i]) - dp;
    dp[j] = a[i];
    ans = max(ans, j + 1);
    int ns = suffix_lds_info[i + 1].second;
    int sl = suffix_lds_info[i + 1].first;
    j = lower_bound(dp, dp + n, ns) - dp;
    if (j) {
      ans = max(ans, j + sl);
    }
  }
  cout << ans << '\n';
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...