Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
- #define ALL(x) x.begin(),x.end()
- #define SZ(x) x.size()
- #define PB push_back
- #define MP make_pair
- #define F first
- #define S second
- typedef long long LL;
- typedef vector<int> VI;
- typedef pair<int,int> PI;
- int n,a[5000],ans,Z[5000][2];
- int solve() {
- Z[0][0] = 1;
- Z[0][1] = 1;
- int cnt = 0;
- for(int i = 1; i < n; i++) {
- for(int j = i-1; j >= 0; j--){
- if(a[j] <= a[i]) Z[i][0] = max(Z[j][1]+1,Z[i][0]);
- if(a[j] >= a[i]) Z[i][1] = max(Z[j][0]+1,Z[i][1]);
- }
- cnt = max(cnt,max(Z[i][0],Z[i][1]));
- }
- return cnt;
- }
- int main() {
- io
- cin >> n;
- for(int i = 0; i < n; i++)
- cin >> a[i];
- cout << solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement