#include<bits/stdc++.h>
#define MAXN 400+10
#define MAX 0x3f3f3f
#define MIN 0
using namespace std;
int n;
int stone[MAXN], sum[MAXN][MAXN];
int dpmin[MAXN][MAXN], dpmax[MAXN][MAXN];
int ansmin = MAX, ansmax = MIN;
int main(){
memset(sum, 0, sizeof(sum));
memset(stone, 0, sizeof(stone));
memset(dpmin, MAX, sizeof(dpmin));
memset(dpmax, MIN, sizeof(dpmax));
scanf("%d",&n);
for(int i=1; i<=n; ++i)
{
scanf("%d",&stone[i]);
stone[i+n] = stone[i];
}
for(int i=1; i<=2*n; ++i){
for(int j=i; j<=2*n; ++j)
{
for(int k=i; k<=j; ++k)
{
sum[i][j] += stone[k];
}
}
}
for(int i=1; i<=2*n; ++i)
{
dpmin[i][i] = 0;
}
for(int len=2; len<=n; ++len)
{
for(int l=1; l<=n; ++l)
{
int r = l+len-1;
for(int k=l; k<r; ++k)
{
dpmin[l][r] = min(dpmin[l][r], dpmin[l][k]+dpmin[k+1][r]+sum[l][r]);
dpmax[l][r] = max(dpmax[l][r], dpmax[l][k]+dpmax[k+1][r]+sum[l][r]);
// cout<<" L="<<l<<"; "<<"R="<<r<<endl<<"MIN= "<<dpmin[l][r]<<endl<<"MAX= "<<dpmax[l][r]<<endl;
}
}
}
for(int i=1; i<=n; ++i)
{
ansmin = min(ansmin, dpmin[i][i+n-1]);
ansmax = max(ansmax, dpmax[i][i+n-1]);
}
printf("%d\n%d",ansmin,ansmax);
return 0;
}
谢大佬(跪谢)