제출 #763641

#제출 시각아이디문제언어결과실행 시간메모리
763641AutomatiC__Global Warming (CEOI18_glo)C++17
100 / 100
110 ms5828 KiB
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cctype> #include <iomanip> #include <algorithm> #include <cmath> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <cstdlib> #include <bitset> #include <deque> #define inf 0x3f3f3f3f #define infll 0x3f3f3f3f3f3f3f3fll using namespace std; typedef long long ll; typedef unsigned long long ull; const int maxn = 200005; int a[maxn]; int n, x; int f[maxn], g[maxn]; // f prefix, g suffix int main() { cin >> n >> x; for (int i = 1; i <= n; i++) cin >> a[i]; vector<int> dp1; for (int i = 1; i <= n; i++) { if (dp1.empty() || a[i] > dp1.back()) { dp1.push_back(a[i]); f[i] = dp1.size(); } else { int pos = lower_bound(dp1.begin(), dp1.end(), a[i]) - dp1.begin(); dp1[pos] = a[i]; f[i] = pos + 1; } } vector<int> dp2(n + 2, inf); for (int i = n; i >= 1; i--) { int pos1 = lower_bound(dp2.begin(), dp2.end(), -(a[i] - x)) - dp2.begin(); int pos2 = lower_bound(dp2.begin(), dp2.end(), -a[i]) - dp2.begin(); dp2[pos2] = -a[i]; g[i] = pos1; } int ans = 0; for (int i = 1; i <= n; i++) { ans = max(ans, f[i] + g[i]); } cout << ans << endl; return 0; }
#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...