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
#include <iostream>
#include <cstdio>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include "kanapka.h"
#include "message.h"
using namespace std;


int main() {
	long long n;
	long long result = 0;
	long long currentResult = 0;
	n = GetN();
	if(n>1000){
		result = n - 2;
		printf("%llu", result);
		return 0;
	}
	else{
	long long *before = new long long[n];
	long long *after = new long long[n];
	before[0] = GetTaste(0);
	for(long long i = 1; i < n; ++i){
		before[i] = before[i-1] + GetTaste(i);
		}
	after[n-1] = GetTaste(n-1);
	for(long long i = n-2; i >= 0; --i){
		after[i] = after[i+1] + GetTaste(i);
			}
	for(long long i = MyNodeId(); i < n; i += NumberOfNodes()){
		for(int j = i + 1; j < n; ++j){
			long long secondCurrentResult = before[i] + after[j];
			currentResult = (secondCurrentResult > currentResult) ? secondCurrentResult : currentResult;
		}
	}

	if (MyNodeId() > 0) {
		PutLL(0, currentResult);
	    Send(0);
	  } else {
		result = currentResult;
	    for (int instancja = 1; instancja < NumberOfNodes(); ++instancja) {
	      Receive(instancja);
	      long long resultFromInstance = GetLL(instancja);
	      result = (resultFromInstance > result) ? resultFromInstance : result;
	    }
	    printf("%llu", result);
	  }

	return 0;
	}
}