1 #include<cstdio>
2 #include<algorithm>
3 #include<cstring>
4 using namespace std;
5 const int MAXN = 210;
6 int dp1[MAXN][MAXN],dp2[MAXN][MAXN],a[MAXN],sum[MAXN];
7 int n,ans1 = 2147483647,ans2 = 0;
8
9 int main()
10 {
11 scanf("%d",&n);
12 for (int i=1; i<=n*2; ++i)
13 for (int j=i+1; j<=n*2; ++j)
14 dp1[i][j] = 1e8; //最小值
15 memset(dp2,0,sizeof(dp2)); //最大值
16 for (int i=1; i<=n; ++i)
17 {
18 scanf("%d",&a[i]);
19 a[i+n] = a[i];
20 }
21 for (int i=1; i<=n*2; ++i)
22 sum[i] = sum[i-1]+a[i];
23 for (int i=2*n-1; i>=1; --i)//从倒数第二个开始枚举左端点
24 for (int j=i+1; j<=2*n; ++j)//枚举右端点
25 for (int k=i; k<=j-1; ++k)//枚举中间点
26 dp1[i][j] = min(dp1[i][j],dp1[i][k]+dp1[k+1][j]+sum[j]-sum[i-1]),
27 dp2[i][j] = max(dp2[i][j],dp2[i][k]+dp2[k+1][j]+sum[j]-sum[i-1]);
28 for (int i=1; i<=n; ++i)
29 {
30 ans1 = min(ans1,dp1[i][i+n-1]);
31 ans2 = max(ans2,dp2[i][i+n-1]);
32 }
33 printf("%d\n%d",ans1,ans2);
34 return 0;
35 }