#include<bits/stdc++.h> #define PII pair<int,int> #define f first #define s second #define VI vector<int> #define LL long long #define MP make_pair #define LD long double #define PB push_back #define ALL(V) V.begin(),V.end() #define abs(x) max((x),-(x)) #define PDD pair<LD,LD> #define VPII vector< PII > #define siz(V) ((int)V.size()) #define FOR(x, b, e) for(int x=b;x<=(e);x++) #define FORD(x, b, e) for(int x=b;x>=(e);x--) #define REP(x, n) for(int x=0;x<(n);x++) #define mini(a,b) a=min(a,b) #define maxi(a,b) a=max(a,b) using namespace std; #include "kanapka.h" #include "message.h" int n; int NODES,ID; const int MXNODES=101; LL pref[MXNODES]; LL suf[MXNODES]; LL summ[MXNODES]; main() { NODES = NumberOfNodes(); ID = MyNodeId(); n = GetN(); int SIZ=n/NODES+1; int poc=SIZ*ID; int kon=min(poc+SIZ-1,n-1); LL sum=0; LL res=1e18; LL mipref=0; LL mxpref=0; LL misuf=0; FOR(i,poc,kon) { int x=GetTaste(i); sum+=x; mini(res,sum-mxpref); maxi(mxpref,sum); mini(mipref,sum); } sum=0; FORD(i,kon,poc) { LL x=GetTaste(i); sum+=x; mini(misuf,sum); } PutLL(0,res); PutLL(0,sum); PutLL(0,mipref); PutLL(0,misuf); Send(0); if(ID == 0) { LL sumall=0; LL res=1e18; REP(i,NODES) { Receive(i); LL x=GetLL(i); mini(res,x); summ[i]=GetLL(i); sumall+=summ[i]; pref[i]=GetLL(i); suf[i]=GetLL(i); } REP(i,NODES) { LL pom=0; FOR(j,i+1,NODES-1) { mini(res,suf[i]+pref[j]+pom); pom+=summ[j]; } } cout<<sumall-res<<endl; } }
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 | #include<bits/stdc++.h> #define PII pair<int,int> #define f first #define s second #define VI vector<int> #define LL long long #define MP make_pair #define LD long double #define PB push_back #define ALL(V) V.begin(),V.end() #define abs(x) max((x),-(x)) #define PDD pair<LD,LD> #define VPII vector< PII > #define siz(V) ((int)V.size()) #define FOR(x, b, e) for(int x=b;x<=(e);x++) #define FORD(x, b, e) for(int x=b;x>=(e);x--) #define REP(x, n) for(int x=0;x<(n);x++) #define mini(a,b) a=min(a,b) #define maxi(a,b) a=max(a,b) using namespace std; #include "kanapka.h" #include "message.h" int n; int NODES,ID; const int MXNODES=101; LL pref[MXNODES]; LL suf[MXNODES]; LL summ[MXNODES]; main() { NODES = NumberOfNodes(); ID = MyNodeId(); n = GetN(); int SIZ=n/NODES+1; int poc=SIZ*ID; int kon=min(poc+SIZ-1,n-1); LL sum=0; LL res=1e18; LL mipref=0; LL mxpref=0; LL misuf=0; FOR(i,poc,kon) { int x=GetTaste(i); sum+=x; mini(res,sum-mxpref); maxi(mxpref,sum); mini(mipref,sum); } sum=0; FORD(i,kon,poc) { LL x=GetTaste(i); sum+=x; mini(misuf,sum); } PutLL(0,res); PutLL(0,sum); PutLL(0,mipref); PutLL(0,misuf); Send(0); if(ID == 0) { LL sumall=0; LL res=1e18; REP(i,NODES) { Receive(i); LL x=GetLL(i); mini(res,x); summ[i]=GetLL(i); sumall+=summ[i]; pref[i]=GetLL(i); suf[i]=GetLL(i); } REP(i,NODES) { LL pom=0; FOR(j,i+1,NODES-1) { mini(res,suf[i]+pref[j]+pom); pom+=summ[j]; } } cout<<sumall-res<<endl; } } |