#include <iostream>
using namespace std;
void Lis_inc(int a[],int n)
{
int i,j;
int *f = new int [n];
f[0] = a[0];
for (i = 1;i < n;i++)
{
f[i] = a[i];
for (j = 0;j < i ;j++)
if (a[j] < a[i])
f[i] = max(f[i],f[j]+a[i]);
}
int max=-99999;
for (i = 0;i < n;i++)
if(max < f[i])
max = f[i];
cout << max << endl;
}
void Lis_dec(int a[],int n)
{
int i,j;
int *f = new int [n];
f[n-1] = a[n-1];
for (i = n-2;i >= 0;i--)
{
f[i] = a[i];
for (j = n-1;j > i ;j--)
if (a[i] > a[j])
f[i] = max(f[i],f[j]+a[i]);
}
int max = -999999;
for (i = 0;i < n;i++)
if(max < f[i])
max = f[i];
cout << max << endl;
}
int main()
{
int a[]={10,7,3,5,9,4,8};
Lis_inc(a,7);
Lis_dec(a,7);
return 0;
}