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
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
#include <iostream>
#include "maklib.h"
#include "message.h"

using namespace std;

void bla(int a, int b)
{
    int64_t smin=0;
    int64_t smax=0;
    int64_t skok=0;
    int64_t stan = 0;
    bool minlast=false;

    for (int i=a;i<=b;i++)
    {
        int64_t val = ElementAt(i);
        stan +=val;
        skok = max(skok,stan-smin);
        if (stan<smin)
        {
            smin=stan;
            minlast = true;
        }
        else if (stan>smax)
        {
            smax = stan;
            minlast = false;
        }
    }
    int64_t A,B,C;

    if (minlast)
    {
        A=smax;
        B=smin-smax;
        C=stan-smin;
    }else
    {
        A=smin;
        B=smax-smin;
        C=stan-smax;
    }

    PutLL(0,skok);
    PutLL(0,A);
    PutLL(0,B);
    PutLL(0,C);
    Send(0);
}

void odbierze()
{
    int64_t smin=0;
    int64_t smax=0;
    int64_t skok=0;
    int64_t stan = 0;

    for (int i=0;i<NumberOfNodes(); i++)
    {
        int64_t wskok, A[3];

        Receive(i);
        wskok = GetLL(i);
        skok = max(skok, wskok);

        A[0]=GetLL(i);
        A[1]=GetLL(i);
        A[2]=GetLL(i);
        for (int  j=0;j<3;j++)
        {
            int64_t val = A[j];
            stan +=val;
            skok = max(skok,stan-smin);
            if (stan<smin)
            {
                smin=stan;
            }
            else if (stan>smax)
            {
                smax = stan;
            }
        }

    }
    cout<<skok<<endl;
}


int main()
{


    int64_t NoN = NumberOfNodes();
    int64_t IDdd = MyNodeId();

    int a=(IDdd* Size() +NoN)/NoN ;
    int b=((IDdd+1) *Size() +NoN)/NoN-1;

    bla( a ,b);

    if (IDdd == 0)
        odbierze();

    return 0;
}