POJ_2479
来源:互联网 发布:知乎 实木床多少钱 编辑:程序博客网 时间:2024/05/16 19:39
Description
Input
Each test case contains two lines. The first line is an integer n(2<=n<=50000). The second line contains n integers: a1, a2, ..., an. (|ai| <= 10000).There is an empty line after each case.
Output
Sample Input
1101 -1 2 2 3 -3 4 -4 5 -5
Sample Output
13
Hint
Huge input,scanf is recommended.
#include <stdio.h>
#include <iostream>
using namespace std;
int a[50005], m[50005];
const int MIN = -999999999;
int main()
{
int c;
int n;
int i;
int temp, sum, ans;
scanf("%d", &c);
while(c--)
{
scanf("%d", &n);
temp = MIN;
sum = 0;
for(i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
sum += a[i];
if(sum > temp)
temp = sum;
m[i] = temp; // 记录每个字段的最大值。
if(sum < 0)
sum = 0;
}
sum = 0;
temp = MIN;
ans = MIN;
for(i = n; i > 1; i--)
{
sum += a[i];
if(sum > temp)
temp = sum;
ans = max(ans, temp + m[i-1]);
if(sum < 0)
sum = 0;
}
printf("%d\n", ans);
}
return 0;
}
- POJ_2479
- POJ_2479
- POJ_2479 最大连续子序列和
- 关于Download failed. There are no HTTP transports available which can complete the requested request
- map key value的排序问题
- 安装jdk/jre:
- 基于深层神经网络的命名实体识别技术
- int float 定点 浮点他们之间的关系
- POJ_2479
- POJ 1845 Sumdiv(求逆元)
- Android 设置参数至kernel_ois为例
- 胡适:人生有何意义
- C#打印小票自带条形码打印
- 安装eclipse并汉化
- 基于opencv的MFC多摄像机视场标定软件
- lambdaj工具类中的 Lambda.maxFrom方法的实现
- 一个线性方程组的问题