#include "kanapka.h"
#include "message.h"
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
long long TOKanapkas = GetN();
long long endIndex = 0;
long long caterpillarDigest = 0;
long long maxTaste = 0;
for(long long startIndex = MyNodeId(); startIndex < TOKanapkas; startIndex += NumberOfNodes())
{
endIndex = max(startIndex, endIndex);
while(endIndex != TOKanapkas-1 && caterpillarDigest + GetTaste(endIndex+1) >= 0)
{
caterpillarDigest += GetTaste(endIndex+1);
maxTaste = max(maxTaste, caterpillarDigest);
++endIndex;
}
}
if(MyNodeId() > 0)
{
PutLL(0, maxTaste);
Send(0);
}
else
{
for(int i=1; i<NumberOfNodes(); ++i)
{
Receive(i);
maxTaste = max(maxTaste, GetLL(i));
}
cout << maxTaste << "\n";
}
}
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 | #include "kanapka.h" #include "message.h" #include <algorithm> #include <iostream> using namespace std; int main() { long long TOKanapkas = GetN(); long long endIndex = 0; long long caterpillarDigest = 0; long long maxTaste = 0; for(long long startIndex = MyNodeId(); startIndex < TOKanapkas; startIndex += NumberOfNodes()) { endIndex = max(startIndex, endIndex); while(endIndex != TOKanapkas-1 && caterpillarDigest + GetTaste(endIndex+1) >= 0) { caterpillarDigest += GetTaste(endIndex+1); maxTaste = max(maxTaste, caterpillarDigest); ++endIndex; } } if(MyNodeId() > 0) { PutLL(0, maxTaste); Send(0); } else { for(int i=1; i<NumberOfNodes(); ++i) { Receive(i); maxTaste = max(maxTaste, GetLL(i)); } cout << maxTaste << "\n"; } } |
English