#include <cstdio>
#include <algorithm>
#include "kanapka.h"
#include "message.h"
#define ll long long
using namespace std;
int main()
{
    ll N=GetN();
    ll poczatek = (MyNodeId() * N) / NumberOfNodes();
    ll koniec = ((MyNodeId() + 1) * N) / NumberOfNodes();
    //int poczatek = MyNodeId()==0 ? 0 : 0;
    //int koniec = MyNodeId()==0 ? N : 0;
    ll sum=0,suml=0,sumr=0,sumin=0,s=0;
    for (int i = poczatek; i < koniec; ++i) {
        ll a = -GetTaste(i); //printf("%lld\n",a);
        sum += a;
        if (sum>suml) suml=sum;
        if (sum<sumr) sumr=sum;
        s += a;
        if (s<=0)
            s=0;
        else
            if (s>sumin) sumin=s;
    }
    sumr = sum-sumr;
    //printf("[%lld, %lld): %lld %lld %lld %lld\n", poczatek,koniec,sum,suml,sumr,sumin);
    PutLL(0,sum); PutLL(0,suml); PutLL(0,sumr); PutLL(0,sumin);
    Send(0);
    if (MyNodeId()==0) {
        ll best=0,bylo=0,sumac=0;
        for (int i=0; i<NumberOfNodes();i++) {
            Receive(i);
            sum=GetLL(i); suml=GetLL(i); sumr=GetLL(i); sumin=GetLL(i);
            sumac += sum;
            if (sumin>best) best=sumin;
            if (bylo+suml>best) best=bylo+suml;
            bylo = max(bylo+sum,sumr);
        }
        printf("%lld\n",-(sumac-best));
    }
    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 | #include <cstdio> #include <algorithm> #include "kanapka.h" #include "message.h" #define ll long long using namespace std; int main() { ll N=GetN(); ll poczatek = (MyNodeId() * N) / NumberOfNodes(); ll koniec = ((MyNodeId() + 1) * N) / NumberOfNodes(); //int poczatek = MyNodeId()==0 ? 0 : 0; //int koniec = MyNodeId()==0 ? N : 0; ll sum=0,suml=0,sumr=0,sumin=0,s=0; for (int i = poczatek; i < koniec; ++i) { ll a = -GetTaste(i); //printf("%lld\n",a); sum += a; if (sum>suml) suml=sum; if (sum<sumr) sumr=sum; s += a; if (s<=0) s=0; else if (s>sumin) sumin=s; } sumr = sum-sumr; //printf("[%lld, %lld): %lld %lld %lld %lld\n", poczatek,koniec,sum,suml,sumr,sumin); PutLL(0,sum); PutLL(0,suml); PutLL(0,sumr); PutLL(0,sumin); Send(0); if (MyNodeId()==0) { ll best=0,bylo=0,sumac=0; for (int i=0; i<NumberOfNodes();i++) { Receive(i); sum=GetLL(i); suml=GetLL(i); sumr=GetLL(i); sumin=GetLL(i); sumac += sum; if (sumin>best) best=sumin; if (bylo+suml>best) best=bylo+suml; bylo = max(bylo+sum,sumr); } printf("%lld\n",-(sumac-best)); } return 0; } | 
 
            
         English
                    English