#include "kanapka.h"
#include "message.h"
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PI;
typedef long long LL;
typedef double D;
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define R(I,N) for(int I=0;I<N;I++)
#define F(I,A,B) for(int I=A;I<B;I++)
#define FD(I,N) for(int I=N-1;I>=0;I--)
#define make(A) scanf("%d",&A)
#define make2(A,B) scanf("%d%d",&A,&B)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define db if(1)printf
template<typename C> void MA(C& a,C b){if(a<b)a=b;}
template<typename C> void MI(C& a,C b){if(a>b)a=b;}
LL sum,pref,suf,naj;
void licz(int p,int k){
F(i,p,k){
LL pom = GetTaste(i);
sum += pom;
MI(pref, sum);
suf = min(suf + pom, 0ll);
MI(naj, suf);
}
}
int proc,id;
main(){
proc = NumberOfNodes();
id = MyNodeId();
int n = GetN();
int il = (n+proc-1)/proc;
licz(min(il*id,n), min(il*(id+1),n));
if(id == 0){
F(i,1,proc){
Receive(i);
MI(naj, suf + GetLL(i));
MI(naj, GetLL(i));
LL pom = GetLL(i);
suf += pom;
sum += pom;
MI(suf, GetLL(i));
}
printf("%lld\n", sum - naj);
}else{
PutLL(0, pref);
PutLL(0, naj);
PutLL(0, sum);
PutLL(0, suf);
Send(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 | #include "kanapka.h" #include "message.h" #include<bits/stdc++.h> using namespace std; typedef pair<int,int> PI; typedef long long LL; typedef double D; #define FI first #define SE second #define MP make_pair #define PB push_back #define R(I,N) for(int I=0;I<N;I++) #define F(I,A,B) for(int I=A;I<B;I++) #define FD(I,N) for(int I=N-1;I>=0;I--) #define make(A) scanf("%d",&A) #define make2(A,B) scanf("%d%d",&A,&B) #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define db if(1)printf template<typename C> void MA(C& a,C b){if(a<b)a=b;} template<typename C> void MI(C& a,C b){if(a>b)a=b;} LL sum,pref,suf,naj; void licz(int p,int k){ F(i,p,k){ LL pom = GetTaste(i); sum += pom; MI(pref, sum); suf = min(suf + pom, 0ll); MI(naj, suf); } } int proc,id; main(){ proc = NumberOfNodes(); id = MyNodeId(); int n = GetN(); int il = (n+proc-1)/proc; licz(min(il*id,n), min(il*(id+1),n)); if(id == 0){ F(i,1,proc){ Receive(i); MI(naj, suf + GetLL(i)); MI(naj, GetLL(i)); LL pom = GetLL(i); suf += pom; sum += pom; MI(suf, GetLL(i)); } printf("%lld\n", sum - naj); }else{ PutLL(0, pref); PutLL(0, naj); PutLL(0, sum); PutLL(0, suf); Send(0); } } |
English