#include "kanapka.h"
#include "message.h"
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int num=MyNodeId();
int ile=NumberOfNodes();
if(num==0){
int Y=GetN();
if(Y<ile)
ile=Y+1;
long long sum=0, suma=0, mp=0, wyn=0,x;
for(int i=1; i<ile; i++)
{
Receive(i);
x=GetLL(i);
wyn=min(wyn, x);
x=GetLL(i);
wyn=min(wyn, suma+x-mp);
x=GetLL(i);
mp=max(mp, suma+x);
x=GetLL(i);
suma+=x;
}
//printf("%lld %lld\n", GetTaste(0), GetTaste(1) );
printf("%lld\n", suma-wyn);
} else{
long long x=GetN();
if(num>x)
return 0;
if(x<ile)
ile=x+1;
long long pocz=x*(num-1)/(ile-1), kon=x*num/(ile-1)-1;
//printf("%lld %lld\n", pocz, kon);
long long wyn=0, mp=0, mip=0, suma=0;
for(long long i=pocz; i<=kon; i++)
{
long long x=GetTaste(i);
suma+=x;
mp=max(mp, suma);
mip=min(suma, mip);
wyn=min(wyn, suma-mp);
}
PutLL(0, wyn);
PutLL(0, mip);
PutLL(0, mp);
PutLL(0, suma);
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 | #include "kanapka.h" #include "message.h" #include <algorithm> #include <iostream> using namespace std; int main() { int num=MyNodeId(); int ile=NumberOfNodes(); if(num==0){ int Y=GetN(); if(Y<ile) ile=Y+1; long long sum=0, suma=0, mp=0, wyn=0,x; for(int i=1; i<ile; i++) { Receive(i); x=GetLL(i); wyn=min(wyn, x); x=GetLL(i); wyn=min(wyn, suma+x-mp); x=GetLL(i); mp=max(mp, suma+x); x=GetLL(i); suma+=x; } //printf("%lld %lld\n", GetTaste(0), GetTaste(1) ); printf("%lld\n", suma-wyn); } else{ long long x=GetN(); if(num>x) return 0; if(x<ile) ile=x+1; long long pocz=x*(num-1)/(ile-1), kon=x*num/(ile-1)-1; //printf("%lld %lld\n", pocz, kon); long long wyn=0, mp=0, mip=0, suma=0; for(long long i=pocz; i<=kon; i++) { long long x=GetTaste(i); suma+=x; mp=max(mp, suma); mip=min(suma, mip); wyn=min(wyn, suma-mp); } PutLL(0, wyn); PutLL(0, mip); PutLL(0, mp); PutLL(0, suma); Send(0); } return 0; } |
English