제출 #1309502

#제출 시각아이디문제언어결과실행 시간메모리
1309502comet0Global Warming (CEOI18_glo)C++20
17 / 100
252 ms25596 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, ll>; bool g(P a, P b) { return a.first > b.first || (a.first == b.first && a.second < b.second); } P q(map<ll, P>& m, ll k) { auto it = m.lower_bound(k); if (it == m.begin()) return {0, (ll)4e18}; it--; return it->second; } void u(map<ll, P>& m, ll k, P v) { auto it = m.lower_bound(k); P p = it == m.begin() ? P{0, (ll)4e18} : prev(it)->second; if (!g(v, p)) return; if (it != m.end() && it->first == k) it->second = v; else it = m.insert({k, v}).first; for (auto j = next(it); j != m.end() && !g(j->second, v);) { auto t = j++; m.erase(t); } } int main() { int k, x; cin >> k >> x; vector<ll> v(k); for (auto& a : v) cin >> a; map<ll, P> m, n, o, p; int r = 0; for (int i = 0; i < k; i++) { P t = q(m, v[i]); int b = t.first + 1; P c = {1, (ll)-4e18}; t = q(m, v[i] + (ll)x); P s = {t.first + 1, t.second - v[i]}; if (g(s, c)) c = s; t = q(n, v[i]); s = {t.first + 1, t.second}; if (g(s, c)) c = s; int d = 0; t = q(o, v[i]); if (t.first) d = max(d, t.first + 1); t = q(p, v[i]); if (t.first) d = max(d, t.first + 1); u(m, v[i], {b, v[i]}); u(n, v[i], c); if (c.second < x) { ll e = c.second <= -2e18 ? (ll)-4e18 : v[i] + c.second; u(o, e, {c.first, 0}); } if (d) u(p, v[i], {d, 0}); r = max(r, max(b, max(c.first, d))); } cout << r; }
#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...