Max Subarray Sum 2025 (Optional)
Time limit: 500ms
Memory limit: 256mb
Description:
Given an array A of integers with length n, find out the maximum sum of the subarrays in A. Here are some examples:
Input:
The first line contains a non-negative integer N;
The second line contains A, an array of N integers, A[0], A[1], ..., A[N-1];
0 <= N >= 10^3
Output:
The maximum sum of the subarrays in A.
Sample Input 1:
10
6 8 7 7 -4 -4 0 8 6 -5
Sample Output 1:
34
Sample Input 2:
15
-2 -3 6 10 2 10 -1 6 -9 -6 -6 7 0 2 -9
Sample Output 2:
33
-------------------------Copy the following code, complete it and submit-------------------------
#include <stdio.h>
int max_subarray_sum(int A[], int n) {
// WRITE YOUR CODE HERE
}
// DO NOT MODIFY THE CODE BELOW
int main() {
int n, A[1000001], i, result;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &A[i]);
result = max_subarray_sum(A, n);
printf("%d", result);
return 0;
}
-------------------------------------------End of Code-------------------------------------------
Submit