File size: 653 Bytes
c4b0eef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <bits/stdc++.h>
using namespace std;

#define ll long long
ll ara[100009], n, dp[5009][5009];

ll solve(ll pos, ll last)

{
    if(pos > n)
        return 0;
    ll &ret = dp[pos][last];
    if(ret != -1)
        return ret;

    ret = 0;
    if(last == 0 || ( abs(ara[last]) < abs(ara[pos]) && ( (ara[last] < 0 && ara[pos] > 0) || (ara[last] > 0 && ara[pos] < 0) ) ) )
        ret = 1 + solve(pos + 1, pos);

    ret = max(ret, solve(pos + 1, last));

    return ret;
}

int main()

{
    memset(dp, -1, sizeof(dp));
    cin >> n;
    for(ll i = 1; i <= n; i++)
        scanf("%lld", &ara[i]);

    cout << solve(1, 0) << endl;

    return 0;