#include "kanapka.h" #include "message.h" #include <iostream> #include <algorithm> using namespace std; long long t, a, m, i, j, NON, N, MNI; long long sum, minn, minpocz, maxpocz, minpart; int main() { ios_base::sync_with_stdio(0); N = GetN(); NON = NumberOfNodes(); MNI = MyNodeId(); t = N % NON; if (MNI < t) { m = (N / NON) + 1; a = MNI * m; } else { m = N / NON; a = (MNI * m) + t; }; sum = 0; minn = 0; minpocz = 0; maxpocz = 0; minpart = 0; for (i = 0; i < m; i++) { j = GetTaste(i + a); sum = sum + j; minpocz = min(minpocz, sum); maxpocz = max(maxpocz, sum); if (minpart < 0) minpart = minpart + j; else minpart = j; minn = min(minn, minpart); }; if (MNI > 0) { PutLL(0, sum); PutLL(0, minpocz); PutLL(0, minn); PutLL(0, sum - maxpocz); Send(0); } else { long long gsum, gminpocz, gmin, gminkon; minpart = sum - maxpocz; for (i = 1; i < NON; i++) { Receive(i); gsum = GetLL(i); gminpocz = GetLL(i); gmin = GetLL(i); gminkon = GetLL(i); sum = sum + gsum; minn = min(minn, min(gmin, minpart + gminpocz)); minpart = min(gminkon, minpart + gsum); }; cout << sum - minn; }; 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 | #include "kanapka.h" #include "message.h" #include <iostream> #include <algorithm> using namespace std; long long t, a, m, i, j, NON, N, MNI; long long sum, minn, minpocz, maxpocz, minpart; int main() { ios_base::sync_with_stdio(0); N = GetN(); NON = NumberOfNodes(); MNI = MyNodeId(); t = N % NON; if (MNI < t) { m = (N / NON) + 1; a = MNI * m; } else { m = N / NON; a = (MNI * m) + t; }; sum = 0; minn = 0; minpocz = 0; maxpocz = 0; minpart = 0; for (i = 0; i < m; i++) { j = GetTaste(i + a); sum = sum + j; minpocz = min(minpocz, sum); maxpocz = max(maxpocz, sum); if (minpart < 0) minpart = minpart + j; else minpart = j; minn = min(minn, minpart); }; if (MNI > 0) { PutLL(0, sum); PutLL(0, minpocz); PutLL(0, minn); PutLL(0, sum - maxpocz); Send(0); } else { long long gsum, gminpocz, gmin, gminkon; minpart = sum - maxpocz; for (i = 1; i < NON; i++) { Receive(i); gsum = GetLL(i); gminpocz = GetLL(i); gmin = GetLL(i); gminkon = GetLL(i); sum = sum + gsum; minn = min(minn, min(gmin, minpart + gminpocz)); minpart = min(gminkon, minpart + gsum); }; cout << sum - minn; }; return 0; } |