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
#include <stdio.h>
#include <stdlib.h>
//#include "message.h"
/*
long long GetN(void)
{
    long long a;
    //scanf("%llu", &a);
    a = 10;
    return a;
}

long long GetTaste(long long i)
{
    long long a;
    //scanf("%llu", &a);
    //long long int tab[100] = {10,-2,5,-4,3,-5,1};
    long long int tab[100] = {10,-1,-1,-1,5,-1,5,-1,-1,10};
    //long long int tab[100] = {1,1,1,1,1,1,1};
    a = tab[i];
    return a;
}
*/

int main(void)
{
    long long int n, i, p, p1, p2, taste;

    long long max = 0;
    long long sumaL = 0, sumaR = 0, maxL = 0, maxR = 0;

    n = GetN();

    p1 = n * MyNodeId() / NumberOfNodes(); //           p-1)/p
    p2 = n * (MyNodeId() + 1) / NumberOfNodes(); //     p/p

    for(i = 0; i <= p1; i++)
    {
        sumaL += GetTaste(i);
        if(max < sumaL)
            max = sumaL;
    }
    for(i = n-1; i > p1; i--)
    {
        sumaR += GetTaste(i);
        if(max < sumaR)
            max = sumaR;
    }

    for(i = p1; i < p2; i++)
    {
        taste = GetTaste(i);
        if(sumaL == maxL)
            maxL -= taste;
        sumaL += taste;
        if(sumaR == maxR)
            maxR -= taste;
        sumaR -= taste;
        if(max < maxL + maxR)
            max =  maxL + maxR;
    }

    if (MyNodeId() > 0)
    {
        PutInt(0, max);
        Send(0);
    }
    else
    {
        for (p = 1; p < NumberOfNodes(); ++p)
        {
            Receive(p);
            i = GetInt(p);
            if(max < i)
                max = i;
        }
        printf("%llu", max);
    }

    return 0;
}