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
#include "maklib.h"
#include "message.h"

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<tr1/unordered_map>
#include<queue>
#include<cstdlib>
#include<list>
#include<set>
#include<map>
#include<cmath>
#define MP make_pair
#define PB push_back
#define s second
#define f first
#define PII pair<int,int>
#define VPII vector <pair<int,int> >
#define VI vector <int>
#define abs(a) max((a),-(a))
#define LL long long
#define LD long double
#define ALL(x) x.begin(),x.end()
#define PU putchar_unlocked
#define GU getchar_unlocked
#define DBG(x) cerr<<#x<<" "<<(x)<<endl;
using namespace std;
int a,b,c,d,e,f,n,m,mx,l,z,r,k;
int wynik;
char ch;
int INF=1e9+1;
LL tsum[101];
LL tpref[101];
LL tsuf[101];
int X;
LL mxpref=0;
LL mxsuf=0;
LL sum=0,minsum=0;
LL best=0;
void HEAD()
{

    tsum[0]=sum;
    tpref[0]=mxpref;
    tsuf[0]=mxsuf;
    for(int i=1;i<X;i++)
        {
        Receive(i);
        best=max(best,GetLL(i));
        tsum[i]=GetLL(i);
        tpref[i]=GetLL(i);
        tsuf[i]=GetLL(i);
        }
    for(int i=0;i<X;i++)
        {
        sum=0;
        for(int j=i+1;j<X;j++)
            {
            best=max(best,tsuf[i]+tpref[j]+sum);
            sum+=tsum[j];
            }
        }
    printf("%lld\n",best);   
}
main()
{
//cout<<MyNodeId()<<endl;
int n=Size();
X=NumberOfNodes();
int SEGSIZ=n/X+(n%X?1:0);
int poc=SEGSIZ*MyNodeId()+1;
int kon=min(poc+SEGSIZ-1,n);
for(int i=poc;i<=kon;i++)
    {
    sum+=ElementAt(i);
    mxpref=max(mxpref,sum);
    minsum=min(sum,minsum);
    best=max(best,sum-minsum);
    }
sum=0;
for(int i=kon;i>=poc;i--)
    {
    sum+=ElementAt(i);
    mxsuf=max(mxsuf,sum);
    }
if(MyNodeId()>0)
    {  
    PutLL(0,best);
    PutLL(0,sum);
    PutLL(0,mxpref);
    PutLL(0,mxsuf);
    Send(0);
    }
else
    {
    HEAD(); 
    }
}