#include "message.h" #include "maklib.h" #include <iostream> #include <cstdio> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <cmath> #include <algorithm> #include <sstream> #include <stack> #include <cstring> #include <iomanip> #include <ctime> using namespace std; #define pb push_back #define INF 1001001001 #define FOR(i,n) for(int (i)=0;(i)<(n);++(i)) #define FORI(i,n) for(int (i)=1;(i)<=(n);++(i)) #define mp make_pair #define pii pair<int,int> #define ll long long #define vi vector<int> #define SZ(x) ((int)((x).size())) #define fi first #define se second #define wez(n) int (n); scanf("%d",&(n)); #define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m)); #define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k)); inline void pisz(int n) { printf("%d\n",n); } template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";} template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; } #define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl; #define ALL(t) t.begin(),t.end() #define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) #define TESTS wez(testow)while(testow--) #define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i) #define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i) #define REMAX(a,b) (a)=max((a),(b)); #define REMIN(a,b) (a)=min((a),(b)); #define IOS ios_base::sync_with_stdio(0); int main () { int n = Size(); int m = NumberOfNodes(), my = MyNodeId(); if (n < m) { // brut if (my == 0) { ll best = 0, now = 0; REP(i,1,n) { now = max(0LL, now + ElementAt(i)); best = max(best, now); } cout << best << endl; } } else { /*int bl = n / m; // bl >= 1 int from = bl * my + 1, to = bl * (my + 1); // [from,to] if (my == m-1) to = n;*/ int from = (1LL * n * my) / m + 1; int to = (1LL * n * (my + 1)) / m; // [from,to] 1-based ll best = 0, now = 0; ll sumFromStart = 0, bestFromStart = 0; REP(i,from,to) { int ti = ElementAt(i); now = max(0LL, now + ti); best = max(best, now); sumFromStart += ti; bestFromStart = max(bestFromStart, sumFromStart); } ll sumFromEnd = 0, bestFromEnd = 0; REPD(i,to,from) { int ti = ElementAt(i); sumFromEnd += ti; bestFromEnd = max(bestFromEnd, sumFromEnd); } PutLL(0, bestFromStart); PutLL(0, bestFromEnd); PutLL(0, best); PutLL(0, sumFromStart); //PutInt(0, from); PutInt(0, to); Send(0); if (my == 0) { best = 0; vector<ll> bFS, bFE, sum; //vi st, en; FOR(a,m) { Receive(a); bFS.pb(GetLL(a)); bFE.pb(GetLL(a)); best = max(best, GetLL(a)); sum.pb(GetLL(a)); //st.pb(GetInt(a)); en.pb(GetInt(a)); } //DBG(bFS)DBG(bFE)DBG(sum) //DBG(st)DBG(en) FOR(a,m-1) REP(b,a+1,m-1) { ll cand = bFE[a] + bFS[b]; REP(c,a+1,b-1) cand += sum[c]; best = max(best, cand); } cout << best << endl; } } 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 | #include "message.h" #include "maklib.h" #include <iostream> #include <cstdio> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <cmath> #include <algorithm> #include <sstream> #include <stack> #include <cstring> #include <iomanip> #include <ctime> using namespace std; #define pb push_back #define INF 1001001001 #define FOR(i,n) for(int (i)=0;(i)<(n);++(i)) #define FORI(i,n) for(int (i)=1;(i)<=(n);++(i)) #define mp make_pair #define pii pair<int,int> #define ll long long #define vi vector<int> #define SZ(x) ((int)((x).size())) #define fi first #define se second #define wez(n) int (n); scanf("%d",&(n)); #define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m)); #define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k)); inline void pisz(int n) { printf("%d\n",n); } template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";} template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; } #define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl; #define ALL(t) t.begin(),t.end() #define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) #define TESTS wez(testow)while(testow--) #define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i) #define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i) #define REMAX(a,b) (a)=max((a),(b)); #define REMIN(a,b) (a)=min((a),(b)); #define IOS ios_base::sync_with_stdio(0); int main () { int n = Size(); int m = NumberOfNodes(), my = MyNodeId(); if (n < m) { // brut if (my == 0) { ll best = 0, now = 0; REP(i,1,n) { now = max(0LL, now + ElementAt(i)); best = max(best, now); } cout << best << endl; } } else { /*int bl = n / m; // bl >= 1 int from = bl * my + 1, to = bl * (my + 1); // [from,to] if (my == m-1) to = n;*/ int from = (1LL * n * my) / m + 1; int to = (1LL * n * (my + 1)) / m; // [from,to] 1-based ll best = 0, now = 0; ll sumFromStart = 0, bestFromStart = 0; REP(i,from,to) { int ti = ElementAt(i); now = max(0LL, now + ti); best = max(best, now); sumFromStart += ti; bestFromStart = max(bestFromStart, sumFromStart); } ll sumFromEnd = 0, bestFromEnd = 0; REPD(i,to,from) { int ti = ElementAt(i); sumFromEnd += ti; bestFromEnd = max(bestFromEnd, sumFromEnd); } PutLL(0, bestFromStart); PutLL(0, bestFromEnd); PutLL(0, best); PutLL(0, sumFromStart); //PutInt(0, from); PutInt(0, to); Send(0); if (my == 0) { best = 0; vector<ll> bFS, bFE, sum; //vi st, en; FOR(a,m) { Receive(a); bFS.pb(GetLL(a)); bFE.pb(GetLL(a)); best = max(best, GetLL(a)); sum.pb(GetLL(a)); //st.pb(GetInt(a)); en.pb(GetInt(a)); } //DBG(bFS)DBG(bFE)DBG(sum) //DBG(st)DBG(en) FOR(a,m-1) REP(b,a+1,m-1) { ll cand = bFE[a] + bFS[b]; REP(c,a+1,b-1) cand += sum[c]; best = max(best, cand); } cout << best << endl; } } return 0; } |