#include"maklib.h"
#include"message.h"
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
main()
{
int non=NumberOfNodes();
int xx=MyNodeId();
int n=Size();
if(non==1)
{
LL maxw=0,ob=0;
int n=Size();
for(int i=1;i<=n;i++)
{
ob+=(LL)ElementAt(i);
if(ob<0) ob=0;
if(ob>maxw) maxw=ob;
}
printf("%lld\n",maxw);
return 0;
}
else
{
if(xx==0)
{
int rozm=n/(non-1);
int lw=1,pw=rozm;
for(int i=1;i<non;i++)
{
PutInt(i,lw);
if(i==non-1) pw=n;
PutInt(i,pw);
Send(i);
lw+=rozm;
pw+=rozm;
}
long long wyn=0,ob=0;
for(int i=1;i<non;i++)
{
Receive(i);
LL maxw=GetLL(i);
if(ob+maxw>wyn) wyn=ob+maxw;
LL a=GetLL(i);
LL zmi=GetLL(i);
if(ob+zmi>a) ob+=zmi;
else ob=a;
if(ob>wyn) wyn=ob;
}
printf("%lld\n",wyn);
}
else
{
Receive(0);
int start=GetInt(0);
int end=GetInt(0);
long long maxw=0,wyn=0,zmi=0;
for(int i=start;i<=end;i++)
{
LL a=(LL)ElementAt(i);
zmi+=a;
wyn+=a;
if(wyn<0) wyn=0;
if(wyn>maxw) maxw=wyn;
}
PutLL(0,maxw);
PutLL(0,wyn);
PutLL(0,zmi);
Send(0);
}
return 0;
}
return 0;
}
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 | #include"maklib.h" #include"message.h" #include<cstdio> #include<algorithm> using namespace std; typedef long long LL; main() { int non=NumberOfNodes(); int xx=MyNodeId(); int n=Size(); if(non==1) { LL maxw=0,ob=0; int n=Size(); for(int i=1;i<=n;i++) { ob+=(LL)ElementAt(i); if(ob<0) ob=0; if(ob>maxw) maxw=ob; } printf("%lld\n",maxw); return 0; } else { if(xx==0) { int rozm=n/(non-1); int lw=1,pw=rozm; for(int i=1;i<non;i++) { PutInt(i,lw); if(i==non-1) pw=n; PutInt(i,pw); Send(i); lw+=rozm; pw+=rozm; } long long wyn=0,ob=0; for(int i=1;i<non;i++) { Receive(i); LL maxw=GetLL(i); if(ob+maxw>wyn) wyn=ob+maxw; LL a=GetLL(i); LL zmi=GetLL(i); if(ob+zmi>a) ob+=zmi; else ob=a; if(ob>wyn) wyn=ob; } printf("%lld\n",wyn); } else { Receive(0); int start=GetInt(0); int end=GetInt(0); long long maxw=0,wyn=0,zmi=0; for(int i=start;i<=end;i++) { LL a=(LL)ElementAt(i); zmi+=a; wyn+=a; if(wyn<0) wyn=0; if(wyn>maxw) maxw=wyn; } PutLL(0,maxw); PutLL(0,wyn); PutLL(0,zmi); Send(0); } return 0; } return 0; } |
English