#include "message.h"
#include "maklib.h"
#include <cstdio>
using namespace std;
int ni, no, N, b, e, i;
long long a, mp, ms, mc, mm, s;
int main() {
ni = MyNodeId();
no = NumberOfNodes();
N = Size();
if (N < no) {
if (ni > 0) {
return 0;
}
b = 0;
e = N;
} else {
b = ni * N / no;
e = (ni + 1) * N / no;
}
for (i = b; i < e; ++i) {
a = 1LL * ElementAt(i);
s += a;
if (s > mp) {
mp = s;
}
if (s < ms) {
ms = s;
}
if (mc < 0) {
mc = a;
} else {
mc += a;
}
if (mc > mm) {
mm = mc;
}
}
ms = s - ms;
if (ni > 0) {
PutLL(0, mp);
PutLL(0, mm);
PutLL(0, s);
PutLL(0, ms);
Send(0);
return 0;
}
if (N >= no) {
mc = ms;
for (i = 1; i < no; ++i) {
Receive(i);
a = GetLL(i);
if (mc + a > mm) {
mm = mc + a;
}
a = GetLL(i);
if (a > mm) {
mm = a;
}
a = GetLL(i);
mc += a;
a = GetLL(i);
if (a > mc) {
mc = a;
}
}
}
printf("%lld\n", mm);
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | #include "message.h" #include "maklib.h" #include <cstdio> using namespace std; int ni, no, N, b, e, i; long long a, mp, ms, mc, mm, s; int main() { ni = MyNodeId(); no = NumberOfNodes(); N = Size(); if (N < no) { if (ni > 0) { return 0; } b = 0; e = N; } else { b = ni * N / no; e = (ni + 1) * N / no; } for (i = b; i < e; ++i) { a = 1LL * ElementAt(i); s += a; if (s > mp) { mp = s; } if (s < ms) { ms = s; } if (mc < 0) { mc = a; } else { mc += a; } if (mc > mm) { mm = mc; } } ms = s - ms; if (ni > 0) { PutLL(0, mp); PutLL(0, mm); PutLL(0, s); PutLL(0, ms); Send(0); return 0; } if (N >= no) { mc = ms; for (i = 1; i < no; ++i) { Receive(i); a = GetLL(i); if (mc + a > mm) { mm = mc + a; } a = GetLL(i); if (a > mm) { mm = a; } a = GetLL(i); mc += a; a = GetLL(i); if (a > mc) { mc = a; } } } printf("%lld\n", mm); return 0; } |
English