Given a sequence of K integers { N​1​​, N​2​​, ..., N​K​​ }. A continuous subsequence is defined to be { N​i​​, N​i+1​​, ..., N​j​​ } where 1. 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 K (≤). 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
#include <iostream>
#include <vector>
using namespace std; int main()
{
/**计算时间
* 开始7:14
* 结束7:27
*/
int T;
cin>>T;int sum=,tmp,max=-;
vector<int> vec;
vector<int> res;
vector<int> all;
while(T--){
cin>>tmp;
all.push_back(tmp);
vec.push_back(tmp);
sum+=tmp;
if(sum>max) {
max=sum;
res=vec;
}
if(sum<){
sum=;
vec.clear();
}
}
if(max!=-) cout<<max<<" "<<res[]<<" "<<res[res.size()-];
else cout<<<<" "<<all[]<<" "<<all[all.size()-];
system("pause");
return ;
}

最新文章

  1. 基于Maven构建开发第一个Storm项目
  2. post 与 get 在转码的区别
  3. 【转载】解决 Subversion 的 “svn: Can&#39;t convert string from &#39;UTF-8&#39; to native encoding” 错误
  4. 使用CodeMirror在浏览器中实现编辑器的代码高亮效果
  5. Educational Codeforces Round 15 Cellular Network
  6. hdu2085
  7. FZU 2216 The Longest Straight 二分
  8. TREEVIEW拖拽对应修改目录
  9. jquery easy ui 学习 (1)Basic Window
  10. postgres常用类型
  11. Jmeter压力测试环境准备
  12. Python应用场景
  13. 【转】 Python调用(运行)外部程序
  14. &lt;%=pageCount %&gt;
  15. activeMQ (一)
  16. Cubase独占声卡问题
  17. js中得计算问题算式结果拼接成字符串怎么解决
  18. hbase搭建
  19. 从C++到java
  20. mysql找到所有索引

热门文章

  1. centos7 安装 eclipse
  2. 微信小程序 API 数据缓存
  3. jmeter正则表达式提取
  4. JUnit@Before失效
  5. robotframework之常用系统关键字
  6. 【工具安装】kali linux 安装教程
  7. react-native start error Invalid regular expression:
  8. IIS Express 使用方法
  9. 递归算法之排列组合-求一个集合S的m个元素的组合和所有可能的组合情况
  10. Windows.etc\hosts文件