제출 #493209

#제출 시각아이디문제언어결과실행 시간메모리
493209RainbowbunnyGlobal Warming (CEOI18_glo)C++17
100 / 100
55 ms4620 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; const int INF = 1e9; int n, x, sz, ans; int a[MAXN]; int lds[MAXN], dp[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> x; for(int i = 1; i <= n; i++) { cin >> a[i]; dp[i] = -INF; } dp[0] = INF; for(int i = n; i >= 1; i--) { int id = lower_bound(dp, dp + sz + 1, a[i], greater <int> ()) - dp; lds[i] = id; dp[id] = max(dp[id], a[i]); sz = max(sz, id); } ans = sz; sz = 0; for(int i = 1; i <= n; i++) { dp[i] = INF; } dp[0] = -INF; for(int i = 1; i <= n; i++) { int id = lower_bound(dp, dp + sz + 1, a[i]) - dp; int zz = upper_bound(dp, dp + sz + 1, a[i] + x - 1) - dp - 1; ans = max(ans, zz + lds[i]); dp[id] = min(dp[id], a[i]); sz = max(sz, id); } 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...