1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include"message.h"
#include"maklib.h"
#include<iostream>

using namespace std;
long long result=0;
void maxpodtablica()
{
	int maxStartIndex = 0;
	int maxEndIndex = 0;
	long long maxSum = 0;

	long long cumulativeSum = 0;
	int maxStartIndexUntilNow = 0;
	for (int currentIndex = 1; currentIndex <= Size(); currentIndex++) {
		int eachArrayItem = ElementAt(currentIndex);
		cumulativeSum += eachArrayItem;

		if (cumulativeSum>maxSum){
			maxSum = cumulativeSum;
			maxStartIndex = maxStartIndexUntilNow;
			maxEndIndex = currentIndex;
		}
		else if (cumulativeSum<0){
			maxStartIndexUntilNow = currentIndex + 1;
			cumulativeSum = 0;
		}
	}

	if (MyNodeId() == 0)
	{
		result = maxSum;
	}
}

int main() {

	maxpodtablica();
	if (MyNodeId() == 0)
	{
	cout <<result<< endl;
	}
	return 0;
}