제출 #699869

#제출 시각아이디문제언어결과실행 시간메모리
699869nima_aryanGlobal Warming (CEOI18_glo)C++14
0 / 100
68 ms4188 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "algo/debug.h" #endif const int inf = 1e9; vector<int> lis(vector<int> const& a, bool value = false) { int n = (int) a.size(); vector<int> ret(n); vector<int> d(n + 1, inf); d[0] = -inf; for (int i = 0; i < n; ++i) { int j = (int) distance(d.begin(), upper_bound(d.begin(), d.end(), a[i]) ); if (d[j - 1] < a[i] && a[i] < d[j]) { ret[i] = j; d[j] = a[i]; } } if (value) { for (int i = 0; i <= n; ++i) { if (d[i] < inf) { ret[0] = i; } } } return ret; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, x; cin >> n >> x; vector<int> t(n); for (int i = 0; i < n; ++i) { cin >> t[i]; } int ans = lis(t, true).front(); for (int i = 0; i < n; ++i) { t[i] -= x; } vector<int> L = lis(t); for (int i = 0; i < n; ++i) { t[i] += x; } reverse(t.begin(), t.end()); vector<int> R = lis(t); reverse(R.begin(), R.end()); for (int i = 0; i < n; ++i) { ans = max(ans, L[i] + R[i] - 1); } cout << ans << '\n'; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */
#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...