记录编号 471037 评测结果 AAAAAAAAAA
题目名称 [福州培训2010] 最大和 最终得分 100
用户昵称 GravatarHeHe 是否通过 通过
代码语言 C++ 运行时间 0.404 s
提交时间 2017-11-05 19:54:32 内存使用 1.33 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

inline char getc(void) { 
    static char buf[1 << 18], *fs, *ft;
    return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}

inline int read(void) { 
    char tmp = getc(), f = 1;
    int res = 0;
    while(!isgraph(tmp)) tmp = getc();
    if(tmp == '-') f = -1, tmp = getc();
    while(isdigit(tmp)) 
        res = ((res + (res << 2)) << 1) + (tmp ^ 0x30),
        tmp = getc();
    return res * f;
}

#ifndef LOCAL
#   define MAXN (100010)
#else
#   define MAXN (1000)
#endif

int s[MAXN << 1];
int N, n;
int l, r, sum, mx;

int main() { 
#ifndef LOCAL
    freopen("maxsum.in", "r", stdin);
    freopen("maxsum.out", "w", stdout);
#endif
    n = (N = read()) << 1;
    for(int i = 1; i <= N; ++i)
        s[i] = s[i + N] = read();
    l = r = 1;
    for(; r <= n; ++r) { 
        if(r - l == N) sum -= s[l], r = ++l, sum = 0;
        sum += s[r];
        if(sum < 0) l = r + 1, sum = 0;
        mx = max(mx, sum);
    }
    printf("%d\n", mx);
    return 0;
}