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
49
50
51
#include "kanapka.h"
#include "message.h"
#include<cstdio> 
#include<algorithm>
using namespace std;
typedef long long ll;
const ll INF = 1e18;

ll ceil(ll a, ll b) {
	if (a%b == 0) return a/b;
	else return a/b+1;	
}


int main ()
{
	ll n = GetN();
	int node = MyNodeId();
	int num = NumberOfNodes();
	ll part = ceil(n, num);
	ll sum = 0, bestBeg = -INF, bestEnd = -INF;
	for (ll i = node*part; i < (node+1)*part && i < n; i++)
	{
		sum+=GetTaste(i);
		bestBeg = max(bestBeg, sum);
		bestEnd = max(bestEnd, -sum);
	}
	if (node!=0){
	PutLL(0, sum);
	PutLL(0, bestBeg);
	PutLL(0, bestEnd);
	Send(0);}
	if (node == 0)
	{
		
		ll sumOfAll = sum, bestBegOfAll = bestBeg, bestEndOfAll = bestEnd;
		for (int i = 1; i < num; i++)
		{
			Receive(i);
			sum = GetLL(i);
			bestBeg = GetLL(i);
			bestEnd = GetLL(i);
			bestBegOfAll = max(bestBegOfAll, sumOfAll+bestBeg);
			bestEndOfAll = max(bestEndOfAll, -sumOfAll+bestEnd);
			sumOfAll += sum;
		}
		
		printf("%lld\n", bestBegOfAll+sumOfAll+bestEndOfAll);
	}
	return 0;
}