#include "kanapka.h" #include "message.h" #include<algorithm> using namespace std; long long int pref[1000], suf[1000], kpref[1000], ksuf[1000], ins[1000]; int main(){ int size, num; long long int N; size = NumberOfNodes(); num = MyNodeId(); N = GetN(); long long int M=(N/size), P = M*num, K = (M+1)*num; long long int a, mp = 0LL, ms = 0LL, p = 0LL, s = 0LL, mm = 0LL, p1 = 0LL, mp1 = 0LL, r = 0LL; for(long long int i=P; i<K; i++){ a = GetTaste(i); p+=a; mp = max(p, mp); } for(long long int i=K-1; i>=P; i--){ a = GetTaste(i); s+=a; ms = max(s, ms); } for(long long int i = P; i<=K; i++){ if(i!=K) a = GetTaste(i); mp1 = max(mp1, p1); mm = max(mm, mp1+s); s-=a; p1+=a; } if(num == 0){ pref[0] = mp; suf[0] = ms; kpref[0] = p; ksuf[0] = s; ins[0] = mm; for(int i=1; i<size; i++){ Receive(i); pref[i] = GetLL(i); suf[i] = GetLL(i); kpref[i] = GetLL(i); ksuf[i] = GetLL(i); ins[i] = GetLL(i); } a = 0LL; for(int i=0; i<size; i++){ a += kpref[i]; kpref[i] = a; } a = 0LL; for(int i=size-1; i>=0; i--){ a += ksuf[i]; ksuf[i] = a; } r = max(ins[0]+ksuf[1], ins[size-1]+kpref[size-2]); for(int i=1; i<size-1; i++){ r = max(r, ins[i]+kpref[i-1]+ksuf[i+1]); } mp = 0LL; p = 0LL; for(int i=0; i<size; i++){ r = max(r, mp+suf[i+1]+ksuf[i+2]); mp = max(mp, kpref[i]+pref[i+1]); } printf("%lld", r); } else{ PutLL(0, p); PutLL(0, s); PutLL(0, mp); PutLL(0, ms); PutLL(0, mm); Send(0); } 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 | #include "kanapka.h" #include "message.h" #include<algorithm> using namespace std; long long int pref[1000], suf[1000], kpref[1000], ksuf[1000], ins[1000]; int main(){ int size, num; long long int N; size = NumberOfNodes(); num = MyNodeId(); N = GetN(); long long int M=(N/size), P = M*num, K = (M+1)*num; long long int a, mp = 0LL, ms = 0LL, p = 0LL, s = 0LL, mm = 0LL, p1 = 0LL, mp1 = 0LL, r = 0LL; for(long long int i=P; i<K; i++){ a = GetTaste(i); p+=a; mp = max(p, mp); } for(long long int i=K-1; i>=P; i--){ a = GetTaste(i); s+=a; ms = max(s, ms); } for(long long int i = P; i<=K; i++){ if(i!=K) a = GetTaste(i); mp1 = max(mp1, p1); mm = max(mm, mp1+s); s-=a; p1+=a; } if(num == 0){ pref[0] = mp; suf[0] = ms; kpref[0] = p; ksuf[0] = s; ins[0] = mm; for(int i=1; i<size; i++){ Receive(i); pref[i] = GetLL(i); suf[i] = GetLL(i); kpref[i] = GetLL(i); ksuf[i] = GetLL(i); ins[i] = GetLL(i); } a = 0LL; for(int i=0; i<size; i++){ a += kpref[i]; kpref[i] = a; } a = 0LL; for(int i=size-1; i>=0; i--){ a += ksuf[i]; ksuf[i] = a; } r = max(ins[0]+ksuf[1], ins[size-1]+kpref[size-2]); for(int i=1; i<size-1; i++){ r = max(r, ins[i]+kpref[i-1]+ksuf[i+1]); } mp = 0LL; p = 0LL; for(int i=0; i<size; i++){ r = max(r, mp+suf[i+1]+ksuf[i+2]); mp = max(mp, kpref[i]+pref[i+1]); } printf("%lld", r); } else{ PutLL(0, p); PutLL(0, s); PutLL(0, mp); PutLL(0, ms); PutLL(0, mm); Send(0); } return 0; } |