1007 Maximum Subsequence Sum

1007 Maximum Subsequence Sum (25)(25 分)

Given a sequence of K integers { N~1~, N~2~, ..., N~K~ }. A continuoussubsequence is defined to be { N~i~, N~i+1~, ..., N~j~ } where 1 <= i<= j <= K. TheMaximum Subsequenceis the continuous subsequencewhich has the largest sum of its elements. For example, given sequence {-2, 11, -4, 13, -5, -2 }, its maximum subsequence is { 11, -4, 13 } withthe 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 K (<= 10000). The second

line contains K 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 i and j (as shown by the sample

case). If all the K 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:

10 1 4



©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,161评论 0 10
  • 我的PAT系列文章更新重心已移至Github,欢迎来看PAT题解的小伙伴请到Github Pages浏览最新内容。...
    OliverLew阅读 2,812评论 0 0
  • 今天晚上为大公益感召资金的状态比昨天好,昨天内心对他人会有埋怨且沮丧,今天一晚上内心都是愉悦的。当自己怀有感恩...
    罗剑华阅读 1,124评论 0 1
  • 我…是21世纪女性。是一名有点名气的网络歌手,擅长跳舞唱歌和做饭。 活泼,胆子有点小。 有时看小说,觉得那些女主真...
    栀粟阅读 1,326评论 0 1
  • 佯装若无其事 心脏已停止呼吸 难缠的情绪反复发作 痉挛声四起 那也是我们的日期 说多说少也没意义 短暂的相聚 永恒...
    清梦飞扬阅读 2,206评论 1 12