#include <bits/stdc++.h> #include "message.h" #include "kanapka.h" using namespace std; #define int long long int NR = NumberOfNodes(); int ID = MyNodeId(); int n = GetN(); void algo() { int mi=0, ma=0, suma=0, res=0; for( int i=0; i<NR; i++ ) { Receive( i ); int a = GetLL( i ); int b = GetLL( i ); int c = GetLL( i ); int d = GetLL( i ); //cout << a << " " << b << " " << c << " " << d << "\n"; suma += a; res = min( res, b ); res = min( res, suma - a + c - ma ); ma = max( ma, suma - a + d ); //cout << suma << " " << res << " " << ma << "\n"; //cout << endl; } //cout << suma << "\n"; cout << suma-res; } int32_t main() { int left = ID*((n-1)/NR+1); int right = (ID+1)*((n-1)/NR+1); right = min( right, n ); vector<int> v; int suma=0; int res=0; int ma=0; int mi=0; //cout << " " << ID << " " << left << " " << right << " " << n << "\n"; for( int i=left; i<right; i++ ) { v.push_back( GetTaste( i ) ); suma += v.back(); res = min( res, suma-ma ); ma = max( ma, suma ); mi = min( mi, suma ); } PutLL( 0, suma ); PutLL( 0, res ); PutLL( 0, mi ); PutLL( 0, ma ); Send( 0 ); if( ID != 0 ) return 0; algo(); 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 | #include <bits/stdc++.h> #include "message.h" #include "kanapka.h" using namespace std; #define int long long int NR = NumberOfNodes(); int ID = MyNodeId(); int n = GetN(); void algo() { int mi=0, ma=0, suma=0, res=0; for( int i=0; i<NR; i++ ) { Receive( i ); int a = GetLL( i ); int b = GetLL( i ); int c = GetLL( i ); int d = GetLL( i ); //cout << a << " " << b << " " << c << " " << d << "\n"; suma += a; res = min( res, b ); res = min( res, suma - a + c - ma ); ma = max( ma, suma - a + d ); //cout << suma << " " << res << " " << ma << "\n"; //cout << endl; } //cout << suma << "\n"; cout << suma-res; } int32_t main() { int left = ID*((n-1)/NR+1); int right = (ID+1)*((n-1)/NR+1); right = min( right, n ); vector<int> v; int suma=0; int res=0; int ma=0; int mi=0; //cout << " " << ID << " " << left << " " << right << " " << n << "\n"; for( int i=left; i<right; i++ ) { v.push_back( GetTaste( i ) ); suma += v.back(); res = min( res, suma-ma ); ma = max( ma, suma ); mi = min( mi, suma ); } PutLL( 0, suma ); PutLL( 0, res ); PutLL( 0, mi ); PutLL( 0, ma ); Send( 0 ); if( ID != 0 ) return 0; algo(); return 0; } |