码迷,mamicode.com
首页 > 其他好文 > 详细

PAT1007

时间:2016-03-01 17:18:43      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;


int main(void){

int k;
int i,j;

int sum = 0;
int max = 0;
int start,rs;
int end,flag;
vector<int> list;
while(scanf("%d",&k)!=EOF){
sum = 0;
max = -1;
start = 0;
rs = 0;
list.clear();
end = 0;
flag = 0;
for(i=0;i<k;i++){
scanf("%d",&j);
if(j>=0) flag = 1;
sum+=j;
list.push_back(j);
if(sum>max){ max = sum; end = i; rs = start;}
if(sum<=0) {sum = 0; start = i+1;}
}
if(flag==1){
printf("%d %d %d\n",max,list[rs],list[end]);
}else printf("0 %d %d\n",list[0],list[k-1]);
}

return 0;
}

PAT1007

标签:

原文地址:http://www.cnblogs.com/zeroArn/p/5231663.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!