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

#define LL long long

int main(){
    int myNodeId=MyNodeId();
    int numberOfNodes=NumberOfNodes();
    LL n=GetN();
    LL left=myNodeId*n/numberOfNodes;
    LL right=(myNodeId+1)*n/numberOfNodes;

    LL sum=0,ret=0,down=0;
    for(LL i=left;i<right;++i){
        LL v=-GetTaste(i);
        sum+=v;
        down=min(down,sum);
        ret=max(ret,sum-down);
    }
    
    if(myNodeId!=0){
        PutLL(0,sum);
        PutLL(0,ret);
        PutLL(0,down);
        Send(0);
    }else{
        for(int i=1;i<numberOfNodes;++i){
            Receive(i);
            LL s=GetLL(i);
            LL r=GetLL(i);
            LL d=GetLL(i)+sum;
            ret=max(ret,r);
            sum+=s;
            down=min(down,d);
            ret=max(ret,sum-down);
        }
        printf("%lld",-sum+ret);
    }

    return 0;
}