Submission #1165718

#TimeUsernameProblemLanguageResultExecution timeMemory
1165718altern23Global Warming (CEOI18_glo)C++20
15 / 100
24 ms9408 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<ll, ll> #define fi first #define sec second #define ld long double const ll N = 1e5; const ll INF = 4e18; const ll MOD = 1e9 + 7; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc = 1; // cin >> tc; for(;tc--;){ ll n, x; cin >> n >> x; vector<ll> a(n + 5); for(int i = 1; i <= n; i++) cin >> a[i]; vector<pii> ps(n + 5), sf(n + 5); ps[0] = {0, -INF}; sf[n + 1] = {0, INF}; vector<ll> cur; for(int i = 1; i <= n; i++){ if(cur.empty() || cur.back() < a[i] - x){ cur.push_back(a[i] - x); } else{ ll pt = lower_bound(cur.begin(), cur.end(), a[i] - x) - cur.begin(); if(pt != cur.size()) cur[pt] = a[i] - x; } ps[i] = {(ll)cur.size(), cur.back()}; } cur.clear(); for(int i = n; i >= 1; --i){ if(cur.empty() || cur.back() > a[i]){ cur.push_back(a[i]); } else{ ll pt = lower_bound(cur.begin(), cur.end(), a[i]) - cur.begin(); if(pt != cur.size()) cur[pt] = a[i]; } sf[i] = {(ll)cur.size(), cur.back()}; } ll ans = ps[n].fi; for(int i = 0; i <= n; i++){ if(ps[i].sec < sf[i + 1].sec) ans = max(ans, ps[i].fi + sf[i + 1].fi); } 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...