讨论 / wa了3个
ScreamSAW 2012-10-12 09:39:00
点我顶贴 收藏 删除
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<cmath>

#include<algorithm>

using namespace std;

int n,a[200],b,c,ans,sum;

int main()

{

scanf("%d",&n);

for(int i=1;i<=n;i++)

{

scanf("%d",&a[i]);

sum+=a[i];

}

if(n%2==0)

{

for(int i=1;i<=n;i+=2)

b+=a[i];

for(int i=2;i<=n;i+=2)

c+=a[i];

printf("%d %d",max(b,c),min(b,c));

}

if(n%2==1)

{

for(int i=1;i<n;i+=2)

b+=a[i];

for(int i=2;i<=n;i+=2)

c+=a[i];

ans=min(b,c)+a[n];

b=0;

c=0;

for(int i=3;i<=n;i+=2)

b+=a[i];

for(int i=2;i<=n;i+=2)

c+=a[i];

ans=max(ans,min(b,c)+a[1]);

printf("%d %d",ans,sum-ans);

}

return 0;

}

感觉是数据错了

查看更多回复
提交回复