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
107
108
#include "kanapka.h"
#include "message.h"

#include <iostream>
using namespace std;

long long int najnizsza_wartosc(int MAX){
    long long int currentSum=0, minSum=0;
    for(int i=0; i<MAX; i++){
        currentSum += GetTaste(i);
        if(currentSum<minSum){
            minSum = currentSum;
        }else if(currentSum > 0){
            currentSum = 0;
        }
    }
    return minSum;
}

int main() {
    int N = GetN();

    if(MyNodeId()==0){
        Receive(1);
        Receive(2);
        Receive(3);
        Receive(4);
        Receive(5);
        Receive(6);
        Receive(7);
        Receive(8);
        Receive(9);
        cout << GetLL(1) + GetLL(2) +GetLL(3) + GetLL(4) + GetLL(5) + GetLL(6) +GetLL(7) + GetLL(8) + GetLL(9) - najnizsza_wartosc(N) << endl;
    }
    if(MyNodeId() == 1){
        long long int sum=0;
        for(int i=0; i<N/9; i++){
            sum += GetTaste(i);
        }
        PutLL(0,sum);
        Send(0);
    }
    if(MyNodeId() == 2){
        long long int sum=0;
        for(int i=N/9; i<N*2/9; i++){
            sum += GetTaste(i);
        }
        PutLL(0,sum);
        Send(0);
    }
    if(MyNodeId() == 3){
        long long int sum=0;
        for(int i=N*2/9; i<N*3/9; i++){
            sum += GetTaste(i);
        }
        PutLL(0,sum);
        Send(0);
    }
    if(MyNodeId() == 4){
        long long int sum=0;
        for(int i=N*3/9; i<N*4/9; i++){
            sum += GetTaste(i);
        }
        PutLL(0,sum);
        Send(0);
    }
    if(MyNodeId() == 5){
        long long int sum=0;
        for(int i=N*4/9; i<N*5/9; i++){
            sum += GetTaste(i);
        }
        PutLL(0,sum);
        Send(0);
    }
    if(MyNodeId() == 6){
        long long int sum=0;
        for(int i=N*5/9; i<N*6/9; i++){
            sum += GetTaste(i);
        }
        PutLL(0,sum);
        Send(0);
    }
    if(MyNodeId() == 7){
        long long int sum=0;
        for(int i=N*6/9; i<N*7/9; i++){
            sum += GetTaste(i);
        }
        PutLL(0,sum);
        Send(0);
    }
    if(MyNodeId() == 8){
        long long int sum=0;
        for(int i=N*7/9; i<N*8/9; i++){
            sum += GetTaste(i);
        }
        PutLL(0,sum);
        Send(0);
    }
    if(MyNodeId() == 9){
        long long int sum=0;
        for(int i=N*8/9; i<N; i++){
            sum += GetTaste(i);
        }
        PutLL(0,sum);
        Send(0);
    }
    return 0;
}