1​​, N2N_2N​2​​, ..., NKN_KN​K​​ }. A continuous subsequence is defined to be { NiN_iN​i​​, Ni+1N_{i+1}N​i+1​​, ..., NjN_jN​j​​ } where 1≤i≤j≤K1 \le i \le j \le K1≤i≤j≤K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For example, given sequence { -2, 11, -4, 13, -5, -2 }, its maximum subsequence is { 11, -4, 13 } with the largest sum being 20.

Now you are supposed to find the largest sum, together with the first and the last numbers of the maximum subsequence.

Input Specification:

Each input file contains one test case. Each case occupies two lines. The first line contains a positive integer KKK (≤10000\le 10000≤10000). The second line contains KKK numbers, separated by a space.

Output Specification:

For each test case, output in one line the largest sum, together with the first and the last numbers of the maximum subsequence. The numbers must be separated by one space, but there must be no extra space at the end of a line. In case that the maximum subsequence is not unique, output the one with the smallest indices iii and jjj (as shown by the sample case). If all the KKK numbers are negative, then its maximum sum is defined to be 0, and you are supposed to output the first and the last numbers of the whole sequence.

Sample Input:

10
-10 1 2 3 4 -5 -23 3 7 -21

Sample Output:

),第二行输入KKK个数,以空格为分割。输出:对于每一个测试的情况下,在一个行中的最大总和的输出,与第一和最大序列的最后数字。数字必须用一个空格分开,但最后一个数后没有空格。在该最大序列不是唯一的情况下,输出一个具有最小索引的数。如果输入的所有的数都是负数,则它的最大总和被定义为0,你应该输出的第一和整个序列的最后一个数。============================第一次code:

 #include <stdio.h>
 #include <stdlib.h>

 void MaxSubseSum(int n);
 int main(void)
 {
     int n;
     scanf("%d",&n);
     MaxSubseSum(n);
     ;
 }
 void MaxSubseSum(int n)
 {
     ,MaxSum=,start=,end=,start1=,flag=;
     int a[n];
     ;i<n;i++)
     {
        scanf("%d",&a[i]);
     }
     ;i<n;i++)
     {
         ThisSum += a[i];
         )
         flag = ;
         if(ThisSum > MaxSum)
         {
             start = start1;
             MaxSum = ThisSum;
             end = i;
         }
         )
         {
             ThisSum = ;
             start1=i+;
         }
     }
     )
     {
         )
         {
             printf(],a[n-]);
         }
        else
         {
             printf("0 0 0");
         }
     }
     else
     {
         printf("%d %d %d",MaxSum,a[start],a[end]);
     }
 }



PAT - 测试 01-复杂度2 Maximum Subsequence Sum (25分)的更多相关文章

  1. 中国大学MOOC-陈越、何钦铭-数据结构-2015秋 01-复杂度2 Maximum Subsequence Sum (25分)

    01-复杂度2 Maximum Subsequence Sum   (25分) Given a sequence of K integers { N​1​​,N​2​​, ..., N​K​​ }. ...

  2. PTA 01-复杂度2 Maximum Subsequence Sum (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/663 5-1 Maximum Subsequence Sum   (25分) Given ...

  3. 01-复杂度2 Maximum Subsequence Sum (25 分)

    Given a sequence of K integers { N​1​​, N​2​​, ..., N​K​​ }. A continuous subsequence is defined to ...

  4. 1007 Maximum Subsequence Sum (25分) 求最大连续区间和

    1007 Maximum Subsequence Sum (25分)   Given a sequence of K integers { N​1​​, N​2​​, ..., N​K​​ }. A ...

  5. 1007 Maximum Subsequence Sum (25 分)

    1007 Maximum Subsequence Sum (25 分)   Given a sequence of K integers { N​1​​, N​2​​, ..., N​K​​ }. A ...

  6. 数据结构练习 01-复杂度2. Maximum Subsequence Sum (25)

    Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, ...

  7. 01-复杂度2. Maximum Subsequence Sum (25)

    Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, ...

  8. PAT Advanced 1007 Maximum Subsequence Sum (25 分)

    Given a sequence of K integers { N​1​​, N​2​​, ..., N​K​​ }. A continuous subsequence is defined to ...

  9. PAT 1007 Maximum Subsequence Sum (25分)

    题目 Given a sequence of K integers { N​1​​ , N​2​​ , ..., N​K​​ }. A continuous subsequence is define ...

随机推荐

  1. kbengine0.4.20源代码分析(一)

    基于kbengine 0.4.2 MMOPG服务端是一种高品质的工程项目,品读开源的kbe是一种乐趣.本文档我带童鞋们一起领略一下.囿于我知识面和经验方面所限,文中所述之处难免有错误存在,还请读童鞋们 ...

  2. oracle数据库从入门到精通之四

    序列是oracle中较为重要的概念事务对于ddl是不起作用的查询,更新,数据表,约束这些个概念要掌握.在许多数据库之中都会存在一种数据类型--自动增长列,它能够创建流水号12c之前并没有提供这样一个自 ...

  3. 05:统计单词数【NOIP2011复赛普及组第二题】

    05:统计单词数 总时间限制:  1000ms 内存限制:  65536kB 描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次 ...

  4. [转]PHP如何关闭notice级别的错误提示

    1.在php.ini文件中改动error_reporting改为: error_reporting=E_ALL & ~E_NOTICE 2.如果你不能操作php.ini文件,你可以使用如下方法 ...

  5. 在Win8中用批处理创建Oracle数据库时报“Unable to open file”

    这一问题的原因是在运行批处理时使用了“以管理员权限运行”.如果直接双击运行是没有问题的. 如果我就想用管理员权限运行呢? 出这个错误的原因是,以管理员权限运行时的当前目录不是批处理所在的目录了.所以, ...

  6. cordova环境配置

    1,安装node.js 2,安装git 3,安装cordova 安装node.js后,命令行输入:npm install -g cordova 加@版本号可安装指定版本,如:npm istall -g ...

  7. 新安装loadrunner无法录制脚本的原因之一及解决方案

    eg:IE浏览器 1.新安装的loadrunner录制脚本,一直是加载中的状态: 2.苦思冥想终于找到解决方案: 3.IE浏览器-->设置-->Internet选项 4."安全& ...

  8. 一个非常牛比的前端google插件

    WEB前端助手(FeHelper) 用了都说好,嘻嘻

  9. POJ 2352 Stars 线段树 数星星

    转载自 http://www.cnblogs.com/fenshen371/archive/2013/07/25/3214927.html 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标 ...

  10. 使用maven一步一步构建spring mvc项目

    1      使用eclipse构建maven web项目 1.1新建Maven的web项目 打开菜单File –New-MavenProject. 点击Next 选择模板类型archtype——ma ...