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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include"kanapka.h"
#include"message.h"
#include<cstdio>
typedef long long int lld;

lld max(lld a, lld b){
	if(a<b)
		return b;
	return a;
}

lld min(lld a, lld b){
	if(a>b)
		return b;
	return a;
}

lld sum1[1005];
lld sum2[1005];
lld pre1[1005];
lld pre2[1005];

int main(void){
	if(MyNodeId() == 0){
		for(int i=1;i<NumberOfNodes();i++){
			Receive(i);
			pre1[i]=GetLL(i);
			sum1[i]=GetLL(i);

			pre2[i]=GetLL(i);
			sum2[i]=GetLL(i);
		}

		lld wyn1=0;

		for(int i=1;i<NumberOfNodes();i++){
			sum1[i]+=sum1[i-1];
			wyn1=max(wyn1,sum1[i-1]+pre1[i]);
		}

		lld wyn2=0;

		for(int i=NumberOfNodes()-1;i>0;i--){
			sum1[i]+=sum1[i+1];
			wyn2=max(wyn2,sum2[i+1]+pre2[i]);
		}

		printf("%lld\n",wyn1+wyn2);
	}else{
		lld n=GetN();
		lld m=(n+NumberOfNodes()-1)/NumberOfNodes();

		lld a,b;

		a=MyNodeId()-1;
		b=MyNodeId();

		lld sum=0;
		lld max_pref=0;

		for(int i=a*n;i<=min(b*m,n)-1;i++){
			sum+=GetTaste(i);
			max_pref=max(max_pref,sum);
		}

		PutLL(0,max_pref);
		PutLL(0,sum);

		sum=0;
		max_pref=0;

		for(int i=min(b*m,n)-1;i>=a;i--){
			sum+=GetTaste(i);
			max_pref=max(max_pref,sum);
		}

		PutLL(0,max_pref);
		PutLL(0,sum);

		Send(0);
	}

	return 0;
}