标签:flag memory printf iss ret art i++ input mes
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 42744 Accepted Submission(s): 19407
6-2 11 -4 13 -5 -210-10 1 2 3 4 -5 -23 3 7 -216 5 -8 3 2 5 01103-1 -5 -23-1 0 -20
20 11 1310 1 410 3 510 10 100 -1 -20 0 0
#include<bits/stdc++.h> using namespace std; int num[10001]; int main(){ int m; while(scanf("%d",&m) && m){ int nowsum = 0,start = 0,end = 0,flag = 0; for(int i = 0; i < m; i++) scanf("%d",&num[i]); int maxsum = num[0]; for(int i = 0; i < m; i++){ if(nowsum < 0){ nowsum = num[i]; start = i;//重新确定起点 }else nowsum += num[i]; if(nowsum > maxsum){ maxsum = nowsum;//更新最大值 flag = start; end = i; } } if(maxsum >= 0) printf("%d %d %d\n",maxsum,num[flag],num[end]); else printf("0 %d %d\n",num[0],num[m-1]); } return 0; }
标签:flag memory printf iss ret art i++ input mes
原文地址:https://www.cnblogs.com/fangxiaoqi/p/10915446.html