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. English—句子

    1. So far so good.   目前为止,一切都好. 2. Be my guest.     请便.别客气. 3. You're the boss.    听你的. 4.I've heard ...

  2. HotSpotOverview.pdf

    从oracle官网下载的这个HotSpot虚拟机的概况文档,现在翻一下锁的部分: Java 锁 *每一个java对象都是一个潜在的monitor(监视器) >synchronized 关键字 * ...

  3. openjudge-最好的草

    http://noi.openjudge.cn/ch0108/17/ 总时间限制:  10000ms 单个测试点时间限制:  1000ms 内存限制:  65536kB 描述 奶牛Bessie计划好好 ...

  4. chp-adapter 文件结构

    1.需要接口给chp推送数据的Bean,写到/chp-adapter/src/main/java/com/creditharmony/adapter/service 文件夹中,并添加父类,供chp业务 ...

  5. Hue

    Hue是一个开源的Apache Hadoop UI系统,由Cloudera Desktop演化而来,最后Cloudera公司将其贡献给Apache基金会的Hadoop社区,它是基于Python Web ...

  6. Ionic开发实战

    转自:http://blog.csdn.net/i348018533/article/details/47258449/ 折磨的两个月!Ionic从零单排,到项目发布!遇到了很多问题但都一一解决了,此 ...

  7. STM32是否可以跑linux

    操作系统有两种 用MMU的 和 不用MMU的用MMU的是Windows MacOS Linux Android不用MMU的是FreeRTOS VxWorks ucOS... CPU有两种 带MMU的 ...

  8. 为模版设计师而生的Twig(上)-Twig使用指南

    原文地址:http://my.oschina.net/veekit/blog/268828 1. 概要 模板是一个简单的文本文件.它可以生成任何基于文本的格式(HTML.XML.CSV等).它不具有特 ...

  9. [zz] 海洋环境的光能传递

    source: http://cgangs.com/article/2557?source=weibo 就我们的目的来说,海洋环境仅由四部分组成:水表.空气.阳光和水表以下部分.在本节中,我们在数学和 ...

  10. Mysql5.5源码安装步骤笔记记录

    1.cmake软件的安装wget https://cmake.org/files/v3.5/cmake-3.5.0-rc3.tar.gztar xf cmake-3.5.0.tar.gzcd cmak ...