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
#include "maklib.h"
#include "message.h"
#include <cstdio>

#include <algorithm>
using namespace std;

int main() {
	long long int N = Size();

	int node = MyNodeId();

	long long int poczatek = (node * N) / NumberOfNodes();
	long long int koniec = ((node + 1) * N) / NumberOfNodes();

	long long int suma = 0;

	for (long long int i = poczatek; i < koniec; i++) {
		suma += ElementAt(i + 1);
	}

	if (node > 0) {
	   PutLL(0, suma);
	   Send(0);

	} else {
	  for (int i = 1; i < NumberOfNodes(); ++i) {
	  	  int instancja = Receive(-1);
		  suma += GetLL(instancja);	  
	  }
    }
    
    if (node == 0) {
	   printf("%lld\n", suma > 0 ? suma : 0);
	}
    
    return 0;
}