首页 > 学院 > 开发设计 > 正文

1007. Maximum Subsequence Sum (25)

2019-11-08 02:55:19
字体:
来源:转载
供稿:网友
#include <cstdio>#include <iostream>using namespace std;int a[10001];int main(){ int k; scanf("%d", &k); for (int i = 0; i < k; i++){ scanf("%d", &a[i]); } int sum = 0, start = 0, end = k - 1, temp = 0, tempi = 0, tempj = 0; for (int i = 0; i < k; i++){ if (temp >= 0){ temp += a[i]; tempj = i; } else { temp = a[i]; tempi = i; tempj = i; } if (temp > sum ||(temp == 0 && end == k - 1)){//就是 0 0 -1 0 -1,这种情况end 应该等于第二个0 sum = temp; start = tempi; end = tempj; } } PRintf("%d %d %d/n", sum, a[start], a[end]); return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表