比赛 20121023 评测结果 AAAAWWWWWW
题目名称 圆圈舞蹈 最终得分 40
用户昵称 青阳 运行时间 0.043 s
代码语言 C 内存使用 0.60 MiB
提交时间 2012-10-23 20:39:12
显示代码纯文本
#include <stdio.h>
#define min(a, b) ((a)<(b)?(a):(b))
int sum[100001];

int main(void)
{
	int i, j, t, s;
	int n, ans = 0;
	int total = 0;
	freopen("circlea.in", "r", stdin);
	freopen("circlea.out", "w", stdout);
	scanf("%d", &n);
	for(i = 1; i <= n; i++){
		scanf("%d", &t);
		sum[i] = sum[i - 1] + t;
		total += t;
	}
	t = s = 0;
	i = j = 1;
	while(j <= n && i <= n){
		s = min(sum[j] - sum[i - 1], total - (sum[j] - sum[i - 1]));
		if(s <= t){
			if(ans < t){
				ans = t;
			}
			i++;
			t = min(sum[j] - sum[i - 1], total - (sum[j] - sum[i - 1]));
		}else{
			t = s;
			j++;
		}
	}
	if(j > n){
		j--;
		t = min(sum[j] - sum[i - 1], total - (sum[j] - sum[i - 1]));
		while(i <= n){
			s = min(sum[j] - sum[i - 1], total - (sum[j] - sum[i - 1]));
			if(s > t){
				t = s;
			}else{
				break;
			}
			if(ans < s){
				ans = s;
			}
			i++;
		}
	}
	printf("%d\n", ans);
	return 0;
}