#include<cstdio> #include<algorithm> #include<vector> #include<set> #include<map> #include<queue> #include<cmath> #include<iostream> #include<string> #include"message.h" #include"kanapka.h" using namespace std; #define F first #define S second #define MP make_pair #define PB push_back #define LL long long #define PII pair<int, int> #define PLL pair<LL, LL> LL n, res, x, y; int nods, nodn; int p, k; vector<PLL> P; LL a, b, c, d;//left, right, sum, best; int main() { //ios_base::sync_with_stdio(0); nodn=MyNodeId(); nods=NumberOfNodes(); n=GetN(); if(n<nods) { if(nodn>0) return 0; for(int i=0; i<n; i++) { if(i>0) P.PB(MP(GetTaste(i), P[i-1].S)); else P.PB(MP(GetTaste(i), 0)); if(i>0) P[i].F+=P[i-1].F; P[i].S=max(P[i].F, P[i].S); } for(int i=n-1; i>=0; i--) { if(i>0) x+=P[i].F-P[i-1].F; else x+=P[i].F; res=max(res, y+P[i].S); y=max(y, x); } res=max(res, y); printf("%lld\n", res); return 0; } p=((n+nods-1)/nods)*nodn; k=min(p+((n+nods-1)/nods)-1, n-1); if(p>k) { PutLL(0, 0); Send(0); return 0; } for(int i=p; i<=k; i++) { if(i>p) P.PB(MP(GetTaste(i), P[i-p-1].S)); else P.PB(MP(GetTaste(i), 0)); if(i>p) P[i-p].F+=P[i-p-1].F; P[i-p].S=max(P[i-p].F, P[i-p].S); } for(int i=k; i>=p; i--) { if(i>p) x+=P[i-p].F-P[i-p-1].F; else x+=P[i-p].F; y=max(y, x); } if(nodn==0) { PutLL(1, P[k-p].F); PutLL(1, P[k-p].S); Send(1); } else { Receive(nodn-1); a=GetLL(nodn-1); b=GetLL(nodn-1); if(k<n) { PutLL(nodn+1, a+P[k-p].F); PutLL(nodn+1, max(b, a+P[k-p].S)); Send(nodn+1); } } if(k==n) { PutLL(nodn-1, P[k-p].F); PutLL(nodn-1, y); Send(nodn-1); } else { Receive(nodn+1); c=GetLL(nodn+1); d=GetLL(nodn+1); if(nodn>0) { PutLL(nodn-1, c+P[k-p].F); PutLL(nodn-1, max(d, c+y)); Send(nodn-1); } } x=c; y=d; for(int i=k; i>=p; i--) { if(i>p) x+=P[i-p].F-P[i-p-1].F; else x+=P[i-p].F; res=max(res, y+max(b, a+P[i-p].S)); y=max(y, x); } res=max(res, y); if(nodn>0) { PutLL(0, res); Send(0); } else { for(int i=1; i<nods; i++) { Receive(i); res=max(res, GetLL(i)); } printf("%lld\n", res); } 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | #include<cstdio> #include<algorithm> #include<vector> #include<set> #include<map> #include<queue> #include<cmath> #include<iostream> #include<string> #include"message.h" #include"kanapka.h" using namespace std; #define F first #define S second #define MP make_pair #define PB push_back #define LL long long #define PII pair<int, int> #define PLL pair<LL, LL> LL n, res, x, y; int nods, nodn; int p, k; vector<PLL> P; LL a, b, c, d;//left, right, sum, best; int main() { //ios_base::sync_with_stdio(0); nodn=MyNodeId(); nods=NumberOfNodes(); n=GetN(); if(n<nods) { if(nodn>0) return 0; for(int i=0; i<n; i++) { if(i>0) P.PB(MP(GetTaste(i), P[i-1].S)); else P.PB(MP(GetTaste(i), 0)); if(i>0) P[i].F+=P[i-1].F; P[i].S=max(P[i].F, P[i].S); } for(int i=n-1; i>=0; i--) { if(i>0) x+=P[i].F-P[i-1].F; else x+=P[i].F; res=max(res, y+P[i].S); y=max(y, x); } res=max(res, y); printf("%lld\n", res); return 0; } p=((n+nods-1)/nods)*nodn; k=min(p+((n+nods-1)/nods)-1, n-1); if(p>k) { PutLL(0, 0); Send(0); return 0; } for(int i=p; i<=k; i++) { if(i>p) P.PB(MP(GetTaste(i), P[i-p-1].S)); else P.PB(MP(GetTaste(i), 0)); if(i>p) P[i-p].F+=P[i-p-1].F; P[i-p].S=max(P[i-p].F, P[i-p].S); } for(int i=k; i>=p; i--) { if(i>p) x+=P[i-p].F-P[i-p-1].F; else x+=P[i-p].F; y=max(y, x); } if(nodn==0) { PutLL(1, P[k-p].F); PutLL(1, P[k-p].S); Send(1); } else { Receive(nodn-1); a=GetLL(nodn-1); b=GetLL(nodn-1); if(k<n) { PutLL(nodn+1, a+P[k-p].F); PutLL(nodn+1, max(b, a+P[k-p].S)); Send(nodn+1); } } if(k==n) { PutLL(nodn-1, P[k-p].F); PutLL(nodn-1, y); Send(nodn-1); } else { Receive(nodn+1); c=GetLL(nodn+1); d=GetLL(nodn+1); if(nodn>0) { PutLL(nodn-1, c+P[k-p].F); PutLL(nodn-1, max(d, c+y)); Send(nodn-1); } } x=c; y=d; for(int i=k; i>=p; i--) { if(i>p) x+=P[i-p].F-P[i-p-1].F; else x+=P[i-p].F; res=max(res, y+max(b, a+P[i-p].S)); y=max(y, x); } res=max(res, y); if(nodn>0) { PutLL(0, res); Send(0); } else { for(int i=1; i<nods; i++) { Receive(i); res=max(res, GetLL(i)); } printf("%lld\n", res); } return 0; } |