include <stdio.h>
int max(int a, int b) {
return (a > b) ? a : b;
}
int max_sub_sum(int arr[], int n) {
if (n == 0) {
return 0;
}
int max_sum = arr[0];
int curr_sum = arr[0];
for (int i = 1; i < n; i++) {
curr_sum = max(arr[i], curr_sum + arr[i]);
max_sum = max(max_sum, curr_sum);
}
return max_sum;
}
int main() {
int n;
printf("請輸入資料的個數:");
scanf("%d", &n);
int arr[100];
printf("依次輸入 %d 個資料:\n", n);
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
int value = max_sub_sum(arr, n);
printf("最大連續子序列和為:%d\n", value);
return 0;
}