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
/*************************************************************************
 *   Zadanie:           Maksymalna podtablica                            *
 *   Zlozonosc czasowa: O(n/inst)                                        *
 *   Wynik:             --/10                                            *
 *************************************************************************/

#include <iostream>
#include <vector>

#include "message.h"
#include "maklib.h"

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define SIZE(c) (int) (c).size()
#define FOREACH(i,c) FOR(i,0,SIZE(c)-1)
#define MIN(x,y) ( ((x) < (y))? (x) : (y) )
#define MAX(x,y) ( ((x) > (y))? (x) : (y) )

typedef long long int LLI;

using namespace std;

/*************************************************************************/

int main()
{
    ios_base::sync_with_stdio(0);

    int v = MyNodeId(), n = NumberOfNodes(), s = Size();

    if (s <= 2000000)
    {
        if (v > 0) return 0;

        vector < LLI > S(s,0);
        LLI ans = 0;

        FOR(i,0,s-1)
        {
            int d = ElementAt(i+1);

            if (i == 0) S[0] = d;
            else
            {
                if (S[i-1] < 0) S[i] = d;
                else S[i] = S[i-1] + d;
            }

            ans = MAX(ans,S[i]);
        }

        cout << ans;

        return 0;
    }
    else
    {
        int left = 1 + ( (v*s) / n ), right = 1 + ( ((v+1)*s) / n ); //moj fragment

        LLI sum = 0;
        FOR(i,0,right-left-1) sum += ElementAt(left+i);

        if (v > 0)
        {
            PutLL(0,sum);
            Send(0);
        }
        else
        {
            FOR(i,1,n-1)
            {
                Receive(i);
                LLI x = GetLL(i);

                sum += x;
            }

            if (ElementAt(s) > 0) cout << sum;
            else cout << 0;
        }
    }

    return 0;
}

/*************************************************************************/