1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "maklib.h"
#include <stdio.h>
int max(int x, int y)
{ return (y > x)? y : x; }

int main()
{
    if (MyNodeId() == 0){
        int max_so_far = 0, max_ending_here = 0;
        int i;
        for(i = 1; i <= Size(); i++)
        {
            max_ending_here = max_ending_here + ElementAt(i);
            if(max_ending_here < 0)
                max_ending_here = 0;
            if(max_so_far < max_ending_here)
                max_so_far = max_ending_here;
        }
        printf("%d\n",max_so_far);
    }
    return 0;
}