#include <bits/stdc++.h> #include "message.h" #include "kanapka.h" using namespace std; int main() { int nodes = NumberOfNodes(); int myNode = MyNodeId(); long long n = GetN(); long long sz = (n + nodes - 1) / nodes; long long from = myNode * sz; long long to = min(n, from + sz); long long sum = 0; long long pre = 0; long long post = 0; long long best = 0; long long curr = 0; vector<long long> v; for (long long i = from; i < to; i++) { long long x = GetTaste(i); v.push_back(x); sum += x; curr += x; curr = min(curr, 0LL); best = min(best, curr); } long long sofar = 0; for (int i = 0; i < v.size(); i++) { long long x = v[i]; sofar += x; pre = min(pre, sofar); } sofar = 0; for (int i = v.size() - 1; i >= 0; i--) { long long x = v[i]; sofar += x; post = min(post, sofar); } PutLL(0, sum); PutLL(0, pre); PutLL(0, post); PutLL(0, best); Send(0); if (myNode == 0) { long long total = 0; long long ans = 0; vector<long long> sums(nodes); vector<long long> pres(nodes); vector<long long> posts(nodes); vector<long long> bests(nodes); for (int node = 0; node < nodes; node++) { Receive(node); sums[node] = GetLL(node); pres[node] = GetLL(node); posts[node] = GetLL(node); bests[node] = GetLL(node); total += sums[node]; } long long cp = 0; for (int node = 0; node < nodes; node++) { ans = min(ans, cp + pres[node]); cp += sums[node]; cp = min(cp, posts[node]); ans = min(ans, bests[node]); } cout << total - ans << 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 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 | #include <bits/stdc++.h> #include "message.h" #include "kanapka.h" using namespace std; int main() { int nodes = NumberOfNodes(); int myNode = MyNodeId(); long long n = GetN(); long long sz = (n + nodes - 1) / nodes; long long from = myNode * sz; long long to = min(n, from + sz); long long sum = 0; long long pre = 0; long long post = 0; long long best = 0; long long curr = 0; vector<long long> v; for (long long i = from; i < to; i++) { long long x = GetTaste(i); v.push_back(x); sum += x; curr += x; curr = min(curr, 0LL); best = min(best, curr); } long long sofar = 0; for (int i = 0; i < v.size(); i++) { long long x = v[i]; sofar += x; pre = min(pre, sofar); } sofar = 0; for (int i = v.size() - 1; i >= 0; i--) { long long x = v[i]; sofar += x; post = min(post, sofar); } PutLL(0, sum); PutLL(0, pre); PutLL(0, post); PutLL(0, best); Send(0); if (myNode == 0) { long long total = 0; long long ans = 0; vector<long long> sums(nodes); vector<long long> pres(nodes); vector<long long> posts(nodes); vector<long long> bests(nodes); for (int node = 0; node < nodes; node++) { Receive(node); sums[node] = GetLL(node); pres[node] = GetLL(node); posts[node] = GetLL(node); bests[node] = GetLL(node); total += sums[node]; } long long cp = 0; for (int node = 0; node < nodes; node++) { ans = min(ans, cp + pres[node]); cp += sums[node]; cp = min(cp, posts[node]); ans = min(ans, bests[node]); } cout << total - ans << endl; } return 0; } |