Time Limit:1000MS

Memory Limit:32768KB

Description

Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.

Input

The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).

Output

​For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.

Sample Input

2

5 6 -1 5 4 -7

7 0 6 -1 1 -6 7 -5

Sample Output

Case 1:

14 1 4

 

Case 2:

7 1 6

以下是代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(){
int n,tn;
int news,s,e,t;
int maxn,sum;
cin>> n;
for(int i=1;i<=n;i++){
sum = 0;
maxn = -20000;
news = s = e = 1;
scanf("%d",&tn);
for(int j=1;j<=tn;j++){
scanf("%d",&t);
sum+= t ;
if(sum > maxn){ //目前的和大于记录和,更新和及起点终点
maxn = sum;
e = j;
s = news;
}
if(sum < 0){//目前的和小于0,则将起点定为下一个数,和为0
sum=0;
news=j+1;
}
}
printf("Case %d:\n%d %d %d\n",i,maxn,s,e);
if(i!=n)printf("\n");
}
}

  

Winter-1-D Max Sum 解题报告及测试数据的更多相关文章

  1. HDU 1003 Max Sum 解题报告

    题目大意:求一串数字中,几个连续数字加起来最大值,并确定起始和最末的位置. 思路:这是一题DP题,但是可以用尺取法来做.我一开始不会,也是看了某大神的代码,然后有人告诉我这是尺取法,现在会了. //尺 ...

  2. HOJ 1003 Max Sum 解题报告

    好几年没有做ACM了,感觉忘得差不多了,这个做着做着就打瞌睡了!言归正传,下面是我的解题思路: 首先的话,我们可以画一个函数图,以输入数组的下标为X轴,以数组的和为Y轴,当数组和小于零时,我们使用备用 ...

  3. Winter-1-B Sum 解题报告及测试数据

    Time Limit:500MS Memory Limit:32768KB Description ​Hey, welcome to HDOJ(Hangzhou Dianzi University O ...

  4. LeetCode 1 Two Sum 解题报告

    LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...

  5. LeetCode 2 Add Two Sum 解题报告

    LeetCode 2 Add Two Sum 解题报告 LeetCode第二题 Add Two Sum 首先我们看题目要求: You are given two linked lists repres ...

  6. LeetCode: Combination Sum 解题报告

    Combination Sum Combination Sum Total Accepted: 25850 Total Submissions: 96391 My Submissions Questi ...

  7. USACO Section2.3 Zero Sum 解题报告 【icedream61】

    zerosum解题报告----------------------------------------------------------------------------------------- ...

  8. 【LeetCode】124. Binary Tree Maximum Path Sum 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcode ...

  9. 【LeetCode】508. Most Frequent Subtree Sum 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

随机推荐

  1. 【H.264/AVC视频编解码技术具体解释】十三、熵编码算法(4):H.264使用CAVLC解析宏块的残差数据

    <H.264/AVC视频编解码技术具体解释>视频教程已经在"CSDN学院"上线,视频中详述了H.264的背景.标准协议和实现,并通过一个实战project的形式对H.2 ...

  2. 剑指 offer set 13 把数组排成最小的数

    总结 1. 给定 3, 32, 321 将他们组合成最小的数, 比如 321323 2. 3    ->   333 32   ->   322 321 ->   321 然后再排序

  3. HashMap实现原理、核心概念、关键问题的总结

    简单罗列一下较为重要的点: 同步的问题 碰撞处理问题 rehash的过程 put和get的处理过程 HashMap基础: HashMap的理论基础:维基百科哈希表 JDK中HashMap的描述:Has ...

  4. 【黑金原创教程】【Modelsim】【第四章】激励文本就是仿真环境

      声明:本文为黑金动力社区(http://www.heijin.org)原创教程,如需转载请注明出处,谢谢! 黑金动力社区2013年原创教程连载计划: http://www.cnblogs.com/ ...

  5. iOS 笔试题

    转:http://blog.sina.com.cn/s/blog_b0c5954101014upb.html 1.截取字符串”20|http://www.621life.com“ 中 ‘|’字符前面及 ...

  6. [算法][LeetCode]Spiral Matrix——螺旋矩阵

    题目要求 Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spir ...

  7. 妙味,结构化模块化 整站开发my100du

    ********************************************************************* 重要:重新审视的相关知识 /* 妙味官网:www.miaov ...

  8. Ubuntu 下 chromium浏览器的标签乱码

    最近使用ubuntu系统,安装了个chromium浏览器,标题不会乱码,不过标签乱码,火狐浏览器没有这个问题,强大的互联网告诉我是少字体的原因,执行下面的指令即可. sudo apt-get inst ...

  9. Python 之 UUID

    UUID是根据MAC以及当前时间等创建的不重复的随机字符串 import uuid # Generate a UUID from a host ID, sequence number, and the ...

  10. linux统计当前文件夹下所有文件的个数

    ls 加 R 选项表示recursive递归