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<iostream>
#include<cstdlib>
#include<cassert>
#include<cstdio>
#include "kanapka.h"
#include "message.h"
using namespace std;
int main()
{
	long long ik=GetN(),sp=0,sl=0,mp=0,ml=0,s=0,n=n=MyNodeId(),m=NumberOfNodes(),ss;
	long long tab[ik][3];
	for(long long x=0;x<ik;x++)tab[x][0]=GetTaste(x);
	for(long long x=0;x<ik;x++){
		sp+=tab[ik-1-x][0];
		sl+=tab[x][0];
		tab[x][1]=sl;
		tab[ik-x-1][2]=sp;
		if(mp<sp)mp=sp;
		if(ml<sl)ml=sl;	
	}
	if(sp>0){
		for(long long x=n;x<ik;x+=m){
			for(long long y=ik-1;y>x;y--)if(tab[x][1]+tab[y][2]>s)s=tab[x][1]+tab[y][2];
		}
	}
	mp=s;
	for(long long x=m-1;x>=0;x--){
		if(x!=0){
			PutLL(x,s);
			Send(x);
		}
		else{
			for(long long y=1;y<m;y++){
				if(y!=n){
					Receive(y);
					ss=GetLL(y);
					if(ss>s)mp=ss;
				}
			}
		}
	}	
	cout<<mp;
	return 0;
}