Submission #754458

#TimeUsernameProblemLanguageResultExecution timeMemory
754458sheldonGlobal Warming (CEOI18_glo)C++14
100 / 100
53 ms4424 KiB
#include <bits/stdc++.h> using namespace std; void solve() { int n, x; cin >> n >> x; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<int> dp; vector<int> longest(n); for (int i = 0; i < n; ++i) { auto it = lower_bound(dp.begin(), dp.end(), a[i]); if (it == dp.end()) { dp.push_back(a[i]); longest[i] = dp.size(); } else { *it = a[i]; longest[i] = it - dp.begin() + 1; } } dp.clear(); int ans = 0; for (int i = n - 1; i >= 0; --i) { auto it = lower_bound(dp.begin(), dp.end(), -a[i] + x); ans = max(ans, int(it - dp.begin()) + longest[i]); it = lower_bound(dp.begin(), dp.end(), -a[i]); if (it == dp.end()) dp.push_back(-a[i]); else *it = -a[i]; } cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); }
#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...