#include <iostream>
#include "maklib.h"
#include "message.h"
using namespace std;
int main() {
if(MyNodeId() == 0) {
long sum = 0;
long max = 0;
int cnt = Size();
int i;
for(i=1; i<=cnt; i++){
sum+=ElementAt(i);
if(sum>max) max = sum;
if(sum<0) sum = 0;
}
cout << max;
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <iostream> #include "maklib.h" #include "message.h" using namespace std; int main() { if(MyNodeId() == 0) { long sum = 0; long max = 0; int cnt = Size(); int i; for(i=1; i<=cnt; i++){ sum+=ElementAt(i); if(sum>max) max = sum; if(sum<0) sum = 0; } cout << max; } } |
English