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
#include "kanapka.h"
#include "message.h"
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
int main()
{
	ll n=GetN(),x=NumberOfNodes(),m=MyNodeId(),qz[233];
	//send (sum, maxpre, maxsuf, max)
	qz[0]=0;
	for(int i=1;i<=x;++i) qz[i]=n/x*i;
	qz[x]=n;
	{
	ll su=0,pr=0,sf=0,mp=0,ms=0,cm=0,mx=0;
	for(int i=qz[m];i<qz[m+1];++i)
	{
		ll v=GetTaste(i);
		su+=v; mp=min(mp,pr+=v);
		mx=min(mx,cm=min(cm+v,0LL));
	}
	for(int i=qz[m+1]-1;i>=qz[m];--i)
		ms=min(ms,sf+=GetTaste(i));
	PutLL(0,su); PutLL(0,mp);
	PutLL(0,ms); PutLL(0,mx);
	Send(0);
	}
	if(m!=0) return 0;
	ll aa=0,bb=0,su[233],mp[233],ms[233],mx[233];
	for(int i=0;i<x;++i)
	{
		Receive(i);
		su[i]=GetLL(i); mp[i]=GetLL(i);
		ms[i]=GetLL(i); mx[i]=GetLL(i);
		aa+=su[i]; bb=min(bb,mx[i]);
	}
	for(int i=0;i<x;++i)
	{
		ll p=0;
		for(int j=i+1;j<x;++j)
			bb=min(bb,mp[j]+ms[i]+p),p+=su[j];
	}
	cout<<aa-bb<<"\n";
}