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
45
46
47
48
#include "message.h"
#include "maklib.h"
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
	int n = Size(), a;
	int ile = n / NumberOfNodes() ;
	int x = ile * ( MyNodeId() + 1 );
	if ( MyNodeId() == NumberOfNodes() - 1 ) x = n;
	long long int pre=0, suma=0, MAX=0, suf=0, z;
	for (int i = 1 + ile * MyNodeId() ; i <= x ; i++ )
	{
		a = ElementAt( i );
		suma+=a;
		pre = max( pre, suma );
		suf+=a;
		suf = max( 0LL, suf );
		MAX = max( MAX, suf );
	}
	if ( MyNodeId() > 0 )
	{
		PutLL(0, pre );
		PutLL(0, suma );
		PutLL(0, MAX );
		PutLL(0, suf );
		Send( 0 );
	}
	else
	{
		for (int i = 1; i < NumberOfNodes(); i ++ )
		{
			Receive( i );
			z = GetLL( i );
			MAX = max( MAX, suf + z );
			z = GetLL( i );
			suma += z;
			suf += z;
			z = GetLL( i );
			MAX = max( MAX, z );
			z = GetLL( i );
			suf = max( suf, z );
		}
		printf("%lld\n",MAX);
	}
}