Submission #533725

#TimeUsernameProblemLanguageResultExecution timeMemory
533725SharkyGlobal Warming (CEOI18_glo)C++17
100 / 100
57 ms8516 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int inf = 1e18; signed main() { ios::sync_with_stdio(0); cin.tie(0); int n, x; cin >> n >> x; vector<int> a(n), L(n), R(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<int> dp(n, inf); int mx = 0; for (int i = 0; i < n; i++) { int j = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin(); dp[j] = a[i]; L[i] = j + 1; } fill(dp.begin(), dp.end(), inf); for (int i = n - 1; i >= 0; i--) { int pos = lower_bound(dp.begin(), dp.end(), -(a[i] - x)) - dp.begin(); R[i] = pos; pos = lower_bound(dp.begin(), dp.end(), -a[i]) - dp.begin(); dp[pos] = -a[i]; } for (int i = 0; i < n; i++) { mx = max(mx, L[i] + R[i]); } cout << mx << "\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...