Submission #1091572

#TimeUsernameProblemLanguageResultExecution timeMemory
1091572stdfloatGlobal Warming (CEOI18_glo)C++17
100 / 100
49 ms4412 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, x; cin >> n >> x; vector<int> a(n); for (auto &i : a) cin >> i; deque<int> v; vector<int> u(n); for (int i = n - 1; i >= 0; i--) { if (v.empty() || v[0] > a[i]) { v.push_front(a[i]); u[i] = (int)v.size(); } else { int t = upper_bound(v.begin(), v.end(), a[i]) - v.begin() - 1; u[i] = (int)v.size() - t; v[t] = a[i]; } } v.clear(); int ans = u[0]; for (int i = 0; i < n; i++) { if (v.empty() || v.back() < a[i]) { ans = max(ans, (int)v.size() + u[i]); v.push_back(a[i]); } else { ans = max(ans, (int)(lower_bound(v.begin(), v.end(), a[i] + x) - v.begin()) + u[i]); v[lower_bound(v.begin(), v.end(), a[i]) - v.begin()] = a[i]; } } cout << ans << '\n'; }
#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...