Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem: D. Remove One Element
- // Contest: Codeforces - Codeforces Round 605 (Div. 3)
- // URL: https://codeforces.com/contest/1272/problem/D
- // Memory Limit: 256 MB
- // Time Limit: 2000 ms
- //
- // Powered by CP Editor (https://cpeditor.org)
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
- template <typename... Args> void logger(string vars, Args &&... values)
- {
- cerr << vars << " = ";
- string delim = "";
- (..., (cerr << delim << values, delim = ", "));
- cerr << endl;
- }
- template <class T> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m)); }
- template <class T> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n)); }
- template <class T, T init> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m, init)); }
- template <class T, T init> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n, init)); }
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using pii = pair<int, int>;
- using vl = vector<ll>;
- using vi = vector<int>;
- int main(int argc, char **argv)
- {
- int n;
- cin >> n;
- vi a(n);
- for (auto &x : a)
- cin >> x;
- using a2i = array<int, 2>;
- vector<a2i> dp(n);
- int ans = 1;
- dp[0][0] = 1, dp[0][1] = 0;
- // dp[i][0] keep all, dp[i][1] skip 1 element
- for (int i = 1; i < n; ++i) {
- if (a[i] > a[i - 1]) {
- dp[i][0] = dp[i - 1][0] + 1;
- dp[i][1] = max(dp[i - 1][0], dp[i - 1][1] + 1);
- } else {
- dp[i][0] = 1;
- dp[i][1] = dp[i - 1][0];
- if (i >= 2 && a[i] > a[i - 2])
- dp[i][1] = max(dp[i][1], dp[i - 2][0] + 1);
- }
- ans = max({ans, dp[i][0], dp[i][1]});
- }
- cout << ans << endl;
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement