Max Subarray Sum
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.
-------------------------Copy the following code, complete it and submit-------------------------
/*
I, <Your Full Name>, am submitting the assignment for
an individual project.
I declare that the assignment here submitted is original except for
source material explicitly acknowledged, the piece of work, or a part
of the piece of work has not been submitted for more than one purpose
(i.e. to satisfy the requirements in two different courses) without
declaration. I also acknowledge that I am aware of University policy
and regulations on honesty in academic work, and of the disciplinary
guidelines and procedures applicable to breaches of such policy and
regulations, as contained in the University website
http://www.cuhk.edu.hk/policy/academichonesty/.
It is also understood that assignments without a properly signed
declaration by the student concerned will not be graded by the
teacher(s).
*/
#include <stdio.h>
int max_subarray_sum(int a[], int n) {
// WRITE YOUR CODE HERE
// HINT: YOU MAY REFER TO THE LECTURE SLIDES
}
// 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-------------------------------------------
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
Submit