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

using namespace std;

int main()
{
    long long S = 0, sump = 0;
    int k = 0;
    int J = NumberOfNodes();
    int j = MyNodeId();
    int N = Size();

    int i = j*N/J;

    while(i < (j+1)*N/J or sump > 0)
    {
        sump += ElementAt(i+1);
        if(sump <= 0)
        {
            sump = 0;
            k = i;
        }
        else
        {
            S = sump;
        }
        ++i;
    }

    if(j > 0)
    {
        PutLL(0,S);
        Send(0);
    }
    else
    {
        int maks = 0;
        for(int i = 1; i < J; ++i)
        {
            int inst = Receive(-1);
            long long maks_inst = GetLL(inst);
            if(maks_inst > maks)
            {
                maks = maks_inst;
            }
        }
        cout << maks << endl;
    }

    return 0;

}