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
#include "message.h"
#include "kanapka.h"
#include <bits/stdc++.h>
using namespace std;
long long g_sum[105], g_min_sum[105], g_min_left[105], g_min_right[105];
int main()
{
	int my_id=MyNodeId(), nodes=NumberOfNodes();
	long long sum=0, min_sum=0, tmp=0, n=GetN(), min_left=0, max_left=0, res=0;
	for(int i=(n*my_id)/nodes; i<(n*(my_id+1))/nodes; ++i)
	{
		int taste=GetTaste(i);
		sum+=taste;
		tmp+=taste;
		if(tmp>0) tmp=0;
		if(tmp<min_sum) min_sum=tmp;
		if(sum<min_left) min_left=sum;
		if(sum>max_left) max_left=sum;
	}
	//printf("Node: %d\n sum=%lld, min_sum=%lld\n\n", my_id, sum, min_sum);
	PutLL(0, sum);
	PutLL(0, min_sum);
	PutLL(0, min_left);
	PutLL(0, sum-max_left);
	Send(0);
	if(my_id!=0) return 0;
	for(int i=0; i<nodes; ++i) Receive(i);
	sum=0;
	for(int i=0; i<nodes; ++i)
	{
		sum+=g_sum[i]=GetLL(i);
		g_min_sum[i]=GetLL(i);
		res=min(res, g_min_sum[i]);
		g_min_left[i]=GetLL(i);
		g_min_right[i]=GetLL(i);
	}
	for(int i=0; i<nodes; ++i) for(int j=i+1; j<nodes; ++j)
	{
		tmp=g_min_right[i]+g_min_left[j];
		for(int k=i+1; k<j; ++k) tmp+=g_sum[k];
		if(tmp<res) res=tmp;
	}
	printf("%lld\n", sum-res);
	return 0;
}