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
#include "message.h"
#include "kanapka.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{	int id = MyNodeId();
	int n = GetN();
	if(n < 1e6)
	{	if(id > 0)
		return 0;
		ll maxim = 0;
		ll sum = 0;
		ll x;
		ll res = 0;
		for(int i = 0; i < n; i++)
			x = GetTaste(i), sum += x, res = min(res, sum - maxim), maxim = max(maxim, sum);
		cout << sum - res;
	}
	int B = (n - 1) / 10 + 1;
	int L = id * B;
	int P = min(n, L + B);
	ll sum = 0;
	ll maxim = 0, res = 0, x;
	for(int i = L; i < P; i++)
		x = GetTaste(i), sum += x, maxim = max(maxim, sum), res = min(res, sum - maxim);
	if(id > 0)
	{	Receive(id - 1);
		ll kek = GetLL(id - 1);
		sum += kek; maxim += kek;
		res += kek;
	}
	if(id < 9)
	{	PutLL(id + 1, res);
		Send(id + 1);
		PutLL(9, res);
		Send(9);
	}
	if(id == 9)
	{	for(int i = 0; i < 9; i++)
		{	Receive(i);
			res = min(res, GetLL(i));
		}
		cout << sum - res;
	}
}