文章
6
粉丝
38
获赞
1
访问
2.6k
#include <iostream>
#include <vector>
using namespace std;
int main() {
int K;
while (cin >> K) {
if (K == 0) break;
vector<int> nums(K);
for (int i = 0; i < K; ++i) {
cin >> nums[i];
}
int maxSum = 0;
int currentSum = 0;
int start = 0, end = 0, tempStart = 0;
bool allNegative = true;
int maxElement = nums[0];
for (int i = 0; i < K; ++i) {
if (nums[i] > maxElement) {
maxElement = nums[i];
}
if (nums[i] >= 0) {
allNegative = false;
}
currentSum += nums[i];
if (currentSum > maxSum) {
maxSum = currentSum;
start = tempStart;
end = i;
}
if (currentSum < 0) {
currentSum = 0;
tempStart = i + 1;
...
登录后发布评论
暂无评论,来抢沙发