#include "kanapka.h" #include "message.h" #include <algorithm> #include <iostream> #include <bits/stdc++.h> #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define FORD(i, a, b) for(int i = (a); i >= (b); --i) #define VAR(v, i) __typeof(i) v=(i) #define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define all(v) (v).begin(),(v).end() #define PII pair<int,int> #define mp make_pair #define st first #define nd second #define pb push_back #define lint long long int #define VI vector<int> using namespace std; int N, nodes, id; lint calosc[105]; lint my_maxi = 0; lint my_mini = 1e18; lint my_ans = 0; lint max_pref[105]; lint min_pref[105]; lint lans[105]; int main() { N = GetN(); nodes = NumberOfNodes(); id = MyNodeId(); nodes = min(nodes, N); if (id >= nodes) return 0; int BLOCK_SIZE = (N+nodes-1)/nodes; int POCZ = id * BLOCK_SIZE; int KON = min(N, (id+1)*BLOCK_SIZE); lint pref = 0; FOR(i,POCZ,KON) { pref += GetTaste(i); my_maxi = max(my_maxi, pref); my_mini = min(my_mini, pref); my_ans = min(my_ans, pref - my_maxi); } PutLL(0, pref); PutLL(0, my_ans); PutLL(0, my_maxi); PutLL(0, my_mini); Send(0); if (id == 0) { lint ans = 0; FOR(i,0,nodes) { Receive(i); calosc[i] = GetLL(i); lans[i] = GetLL(i); max_pref[i] = GetLL(i); min_pref[i] = GetLL(i); } lint sum = 0; FOR(i,0,nodes) sum += calosc[i]; lint sofar = 0; lint m_p = 0; FOR(i,0,nodes) { ans = max(ans, sum - lans[i]); ans = max(ans, sum - (sofar + min_pref[i] - m_p)); m_p = max(m_p, max_pref[i] + sofar); sofar += calosc[i]; } printf("%lld\n", ans); } }
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 84 | #include "kanapka.h" #include "message.h" #include <algorithm> #include <iostream> #include <bits/stdc++.h> #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define FORD(i, a, b) for(int i = (a); i >= (b); --i) #define VAR(v, i) __typeof(i) v=(i) #define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define all(v) (v).begin(),(v).end() #define PII pair<int,int> #define mp make_pair #define st first #define nd second #define pb push_back #define lint long long int #define VI vector<int> using namespace std; int N, nodes, id; lint calosc[105]; lint my_maxi = 0; lint my_mini = 1e18; lint my_ans = 0; lint max_pref[105]; lint min_pref[105]; lint lans[105]; int main() { N = GetN(); nodes = NumberOfNodes(); id = MyNodeId(); nodes = min(nodes, N); if (id >= nodes) return 0; int BLOCK_SIZE = (N+nodes-1)/nodes; int POCZ = id * BLOCK_SIZE; int KON = min(N, (id+1)*BLOCK_SIZE); lint pref = 0; FOR(i,POCZ,KON) { pref += GetTaste(i); my_maxi = max(my_maxi, pref); my_mini = min(my_mini, pref); my_ans = min(my_ans, pref - my_maxi); } PutLL(0, pref); PutLL(0, my_ans); PutLL(0, my_maxi); PutLL(0, my_mini); Send(0); if (id == 0) { lint ans = 0; FOR(i,0,nodes) { Receive(i); calosc[i] = GetLL(i); lans[i] = GetLL(i); max_pref[i] = GetLL(i); min_pref[i] = GetLL(i); } lint sum = 0; FOR(i,0,nodes) sum += calosc[i]; lint sofar = 0; lint m_p = 0; FOR(i,0,nodes) { ans = max(ans, sum - lans[i]); ans = max(ans, sum - (sofar + min_pref[i] - m_p)); m_p = max(m_p, max_pref[i] + sofar); sofar += calosc[i]; } printf("%lld\n", ans); } } |