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

#include <iostream>
#include <climits> 
using namespace std;

int main() {
	long long maxL = 0;
	
	for (long long i = 1+MyNodeId(); i<=Size(); i+=NumberOfNodes()){
		long long suma = 0;
		for (long long j = i; j<=Size(); j++){
			suma += ElementAt(j);
			maxL = max(maxL, suma);
		}
	}
	
	if (MyNodeId() > 0) {
	    PutInt(0, maxL);
	    Send(0);
	}
	else {
	    for (int instancja = 1; instancja < NumberOfNodes(); ++instancja) {
	      Receive(instancja);
	      maxL = max(maxL, (long long)GetInt(instancja));
	    }
	    cout << maxL << endl;
	}
  return 0;
}