只对第一个点,而且第二个全是负数的测试点我的输出竟然是正数QAQ
查看原帖
只对第一个点,而且第二个全是负数的测试点我的输出竟然是正数QAQ
790685
bluetored楼主2022/11/14 16:21
#include<iostream>
using namespace std;
int main() {
	int max = 0,n;
	cin >> n;
	int arr[10001];
	for (int i = 0; i < n; i++) cin >> arr[i];
	for (int i = 0; i < n; i++) {
		int temp = i;
		int sum = 0;
		while (temp < n) {
			sum += arr[temp++];
			if (max < sum||temp==1) max = sum;
		}
	}
	cout << max;
	return 0;
}
2022/11/14 16:21
加载中...