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 "kanapka.h"
#include "message.h"
#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

struct info {
	i64 lans, rans, sum, ans;
	void append(info right){
		ans = min(min(ans, right.ans), rans + right.lans);
		lans = min(lans, sum + right.lans);
		rans = min(right.rans, right.sum + rans);
		sum += right.sum;
	}
	void append(i64 number){
		i64 value = min(number, 0LL);
		ans = min(ans, rans + value);
		lans = min(lans, sum + value);
		rans = min(value, number + rans);
		sum += number;
	}
} result;
int nodes, current_node, n, L, R;

int main(){
	nodes = NumberOfNodes();
	current_node = MyNodeId();
	n = GetN();
	L = current_node * 1.0 / nodes * n;
	R = (current_node + 1) * 1.0 / nodes * n;
	for (int x = L; x < R; ++x) result.append(GetTaste(x));
	if (current_node == 0) {
		for (int x = 1; x < nodes; ++x) {
			Receive(x);
			info get;
			get.lans = GetLL(x), get.rans = GetLL(x), get.sum = GetLL(x), get.ans = GetLL(x);
			result.append(get);
		}
		cout << result.sum - result.ans << endl;
	} else {
		PutLL(0, result.lans), PutLL(0, result.rans), PutLL(0, result.sum), PutLL(0, result.ans);
		Send(0);
	}
}