#include "kanapka.h" #include "message.h" #include <cstdio> #include <algorithm> using namespace std; int main() { int n = GetN(); if (n < 10000) { if (MyNodeId() == 0) { long long s = 0; long long pref = 0; long long suf = 0; long long best = 0; for (int i = 0; i < n; i++) { long long x = GetTaste(i); s += x; suf = min(suf + x, 0LL); best = min(suf, best); } printf("%lld\n", s - best); } return 0; } else { long long left = (1LL * n * MyNodeId() ) / NumberOfNodes(); long long right = (1LL * n * (1LL + MyNodeId()) ) / NumberOfNodes(); long long s = 0; long long pref = 0; long long suf = 0; long long best = 0; for (long long i = left; i < right; i++) { long long x = GetTaste(i); s += x; pref = min(pref, s); suf = min(suf + x, 0LL); best = min(suf, best); } PutLL(0, s); PutLL(0, pref); PutLL(0, suf); PutLL(0, best); Send(0); if (MyNodeId() == 0) { long long last = 0, ret = 0, sum = 0; for (int i = 0; i < NumberOfNodes(); i++) { Receive(i); long long s = GetLL(i); long long pref = GetLL(i); long long suf = GetLL(i); long long best = GetLL(i); ret = min(ret, min(best, last + pref)); last = min(last + s, suf); sum += s; } printf("%lld\n", sum - ret); } } 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 | #include "kanapka.h" #include "message.h" #include <cstdio> #include <algorithm> using namespace std; int main() { int n = GetN(); if (n < 10000) { if (MyNodeId() == 0) { long long s = 0; long long pref = 0; long long suf = 0; long long best = 0; for (int i = 0; i < n; i++) { long long x = GetTaste(i); s += x; suf = min(suf + x, 0LL); best = min(suf, best); } printf("%lld\n", s - best); } return 0; } else { long long left = (1LL * n * MyNodeId() ) / NumberOfNodes(); long long right = (1LL * n * (1LL + MyNodeId()) ) / NumberOfNodes(); long long s = 0; long long pref = 0; long long suf = 0; long long best = 0; for (long long i = left; i < right; i++) { long long x = GetTaste(i); s += x; pref = min(pref, s); suf = min(suf + x, 0LL); best = min(suf, best); } PutLL(0, s); PutLL(0, pref); PutLL(0, suf); PutLL(0, best); Send(0); if (MyNodeId() == 0) { long long last = 0, ret = 0, sum = 0; for (int i = 0; i < NumberOfNodes(); i++) { Receive(i); long long s = GetLL(i); long long pref = GetLL(i); long long suf = GetLL(i); long long best = GetLL(i); ret = min(ret, min(best, last + pref)); last = min(last + s, suf); sum += s; } printf("%lld\n", sum - ret); } } return 0; } |