#include <cstdio> #include <cstdlib> #include <vector> #include <ctime> #include "message.h" #include "kanapka.h" using namespace std; int main(){ long long n = GetN(); long long m = NumberOfNodes(); m = min(n,m); vector<long long> prefixes; vector<long long> suffixes; vector<long long> results; vector<long long> sums; long long pref = 0; long long max_pref = 0; long long suff = 0; long long max_suff = 0; long long result = 0; long long max_here = 0; int id = MyNodeId(); if(id >= m){ return 0; } for(int j=id*n/m; j<(id+1)*n/m; ++j){ long long taste = -GetTaste(j); max_here = max(0LL, max_here+taste); result = max(result, max_here); pref += taste; max_pref = max(pref, max_pref); } for(int j=(id+1)*n/m-1;j>=id*n/m; --j){ long long taste = -GetTaste(j); suff += taste; max_suff = max(suff, max_suff); } PutLL(0,max_pref); PutLL(0,result); PutLL(0,max_suff); PutLL(0,pref); Send(0); if(id == 0){ for(int j=0;j<m;++j){ Receive(j); prefixes.push_back(GetLL(j)); results.push_back(GetLL(j)); suffixes.push_back(GetLL(j)); sums.push_back(GetLL(j)); } } if(id == 0){ result = 0; max_here = 0; long long sum = 0; for(int i = 0; i<m;++i){ sum -= sums[i]; result = max(result, max(max_here + prefixes[i], results[i])); max_here = max(max_here + sums[i], suffixes[i]); } printf("%lld\n", max(sum+result,0LL)); } }
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 <cstdio> #include <cstdlib> #include <vector> #include <ctime> #include "message.h" #include "kanapka.h" using namespace std; int main(){ long long n = GetN(); long long m = NumberOfNodes(); m = min(n,m); vector<long long> prefixes; vector<long long> suffixes; vector<long long> results; vector<long long> sums; long long pref = 0; long long max_pref = 0; long long suff = 0; long long max_suff = 0; long long result = 0; long long max_here = 0; int id = MyNodeId(); if(id >= m){ return 0; } for(int j=id*n/m; j<(id+1)*n/m; ++j){ long long taste = -GetTaste(j); max_here = max(0LL, max_here+taste); result = max(result, max_here); pref += taste; max_pref = max(pref, max_pref); } for(int j=(id+1)*n/m-1;j>=id*n/m; --j){ long long taste = -GetTaste(j); suff += taste; max_suff = max(suff, max_suff); } PutLL(0,max_pref); PutLL(0,result); PutLL(0,max_suff); PutLL(0,pref); Send(0); if(id == 0){ for(int j=0;j<m;++j){ Receive(j); prefixes.push_back(GetLL(j)); results.push_back(GetLL(j)); suffixes.push_back(GetLL(j)); sums.push_back(GetLL(j)); } } if(id == 0){ result = 0; max_here = 0; long long sum = 0; for(int i = 0; i<m;++i){ sum -= sums[i]; result = max(result, max(max_here + prefixes[i], results[i])); max_here = max(max_here + sums[i], suffixes[i]); } printf("%lld\n", max(sum+result,0LL)); } } |