#include "message.h"
#include <iostream>
#include "maklib.h"
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
int sprawdzone=0,tmp;
long long max=0;
long long suma;
while(MyNodeId()+1+sprawdzone*NumberOfNodes() <= Size())
{
tmp=MyNodeId()+1+sprawdzone*NumberOfNodes();
suma=ElementAt(tmp);
if(suma>max)
max=suma;
for(int i=tmp+1;i<=Size();i++)
{
suma += ElementAt(i);
if(suma > max)
{
max=suma;
}
}
sprawdzone++;
}
long long pom;
if(MyNodeId() > 0)
{
PutLL(0, max);
Send(0);
}
else
{
for (int instancja = 1; instancja < NumberOfNodes(); ++instancja)
{
Receive(instancja);
pom= GetLL(instancja);
if( pom > max )
max=pom;
}
if(max>0)
cout<<max;
else
cout<<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 | #include "message.h" #include <iostream> #include "maklib.h" using namespace std; int main() { ios_base::sync_with_stdio(0); int sprawdzone=0,tmp; long long max=0; long long suma; while(MyNodeId()+1+sprawdzone*NumberOfNodes() <= Size()) { tmp=MyNodeId()+1+sprawdzone*NumberOfNodes(); suma=ElementAt(tmp); if(suma>max) max=suma; for(int i=tmp+1;i<=Size();i++) { suma += ElementAt(i); if(suma > max) { max=suma; } } sprawdzone++; } long long pom; if(MyNodeId() > 0) { PutLL(0, max); Send(0); } else { for (int instancja = 1; instancja < NumberOfNodes(); ++instancja) { Receive(instancja); pom= GetLL(instancja); if( pom > max ) max=pom; } if(max>0) cout<<max; else cout<<0; } return 0; } |
English