#include <iostream> #include <vector> #include "maklib.h" #include "message.h" using namespace std; int main() { if (MyNodeId()==0) { int max_so_far = ElementAt(1), max_ending_here = ElementAt(1); for(size_t i = 2; i <= Size(); i++) { if(max_ending_here < 0) { max_ending_here = ElementAt(i); } else { max_ending_here += ElementAt(i); } if(max_ending_here >= max_so_far ) { max_so_far = max_ending_here; } } cout << max_so_far << endl; } 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 | #include <iostream> #include <vector> #include "maklib.h" #include "message.h" using namespace std; int main() { if (MyNodeId()==0) { int max_so_far = ElementAt(1), max_ending_here = ElementAt(1); for(size_t i = 2; i <= Size(); i++) { if(max_ending_here < 0) { max_ending_here = ElementAt(i); } else { max_ending_here += ElementAt(i); } if(max_ending_here >= max_so_far ) { max_so_far = max_ending_here; } } cout << max_so_far << endl; } return 0; } |