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
#include "maklib.h"
#include "message.h"
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
	long long N = Size();
   long long start = (MyNodeId() * N) / NumberOfNodes();
  	long long stop = ((MyNodeId() + 1) * N) / NumberOfNodes();
   long long int pocz=0,kon=0,act=0,el,wyn=0,poczP,konP,wynP;
   for(int i=start;i<stop;++i){
   	el=ElementAt(i);
   	if(act+el<0){
   		if(pocz==0){
   			pocz=act;
   		}
   		act=0;
   	}else{
   		act+=el;
   	}
   	wyn=max(wyn,act);
   	kon=act;
   }
   int lN=NumberOfNodes()-1;
   if(MyNodeId()<lN){
   	PutLL(lN,pocz);
   	PutLL(lN,kon);
   	PutLL(lN,wyn);
   	Send(lN);
   }else{
   	for(int inst=0;inst<lN;++inst){
   		Receive(inst);
   		poczP=GetLL(inst);
   		konP=GetLL(inst);
   		wynP=GetLL(inst);
   		
   		wyn=max(wyn,wynP);
   		wyn=max(wyn,kon+poczP);
   		kon=konP;
   	}
   	printf("%d\n",wyn);
   }
  	return 0;
}