#include "kanapka.h" #include "message.h" #include <iostream> #include <algorithm> using namespace std; int main() { int instancje=NumberOfNodes(), MyId=MyNodeId(); long long n=GetN(); long long wynik=0, wynik2; for(int i=0; i<n; i++) wynik+=GetTaste(i); long long res=wynik; wynik2=wynik; for(int i=MyId; i<n; i+=instancje) { wynik=wynik2; for(int j=i; j<n; j++) { wynik-=GetTaste(j); if(wynik>res) res=wynik; } } if(MyId>0) { PutLL(0,res); Send(0); } else { for(int i=1; i<instancje; i++) { Receive(i); wynik=GetLL(i); if(wynik>res) res=wynik; } cout<<res; } }
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 | #include "kanapka.h" #include "message.h" #include <iostream> #include <algorithm> using namespace std; int main() { int instancje=NumberOfNodes(), MyId=MyNodeId(); long long n=GetN(); long long wynik=0, wynik2; for(int i=0; i<n; i++) wynik+=GetTaste(i); long long res=wynik; wynik2=wynik; for(int i=MyId; i<n; i+=instancje) { wynik=wynik2; for(int j=i; j<n; j++) { wynik-=GetTaste(j); if(wynik>res) res=wynik; } } if(MyId>0) { PutLL(0,res); Send(0); } else { for(int i=1; i<instancje; i++) { Receive(i); wynik=GetLL(i); if(wynik>res) res=wynik; } cout<<res; } } |