Skip to content

Instantly share code, notes, and snippets.

@pinkogeneral
Created January 16, 2022 17:29
Show Gist options
  • Save pinkogeneral/c734458ddad2eb46b3bb7977add4138f to your computer and use it in GitHub Desktop.
Save pinkogeneral/c734458ddad2eb46b3bb7977add4138f to your computer and use it in GitHub Desktop.
InC = { 1, 2, 2, 1, 3, 3, 4, 5, 2, 1 }
DeC = { 1, 5, 2, 1, 4, 3, 3, 3, 2, 1 }
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{
std::ios::sync_with_stdio(false);
std::cin.tie();
std::cout.tie();
// ===========================
int N; cin >> N;
vector<int> seq(N);
for (int i = 0; i < N; i++)
cin >> seq[i];
// ===========================
vector<int> InC(N,1), DeC(N,1);
for(int i =1; i < N; i++)
for (int j = 0; j < i; j++)
{
if (seq[i] > seq[j])
InC[i] = max(InC[j] + 1, InC[i]);
if(seq[N-i-1]>seq[N-j-1])
DeC[N - i - 1] = max(DeC[N - j - 1 ] + 1, DeC[N - i - 1]);
}
// ===========================
int _max = -1000;
for (int i = 0; i < N; i++)
{
if (_max < InC[i] + DeC[i])
_max = InC[i] + DeC[i];
}
cout << _max - 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment