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
#include "kanapka.h"
#include "message.h"

#include <iostream>

using namespace std;


int main() {
	if(MyNodeId()!=0) return 0;

	long long sumleft=0LL;
	long long sumright=0LL;
	long long bigvalleft=0LL;
	long long bigvalright=0LL;
	long long bigvalleftID=0LL;
	long long bigvalrightID=0LL;
	for( int i=0; i<GetN();i++){
		sumleft+=GetTaste(i);
		//cout<<sumleft<<endl;
		if(sumleft>bigvalleft){
			bigvalleft=sumleft;
			bigvalleftID=i;
		}
	}
	for( int i=GetN()-1; i>=0;i--){
		sumright+=GetTaste(i);
		if(sumright>bigvalright){
			bigvalright=sumright;
			bigvalrightID=i;
		}
	}
	if(bigvalleftID>bigvalrightID){
		long long sumleft1=0LL;
		long long sumright1=0LL;
		long long bigvalleft1=0LL;
		long long bigvalright1=0LL;
		long long bigvalleftID1=0LL;
		long long bigvalrightID1=0LL;
		for( int i=0; i<=bigvalleftID;i++){
			sumleft1+=GetTaste(i);
			//cout<<sumleft1<<endl;
			if(sumleft1>bigvalleft1){
				bigvalleft1=sumleft1;
				bigvalleftID1=i;
			}
		}
		for( int i=GetN()-1; i>bigvalleftID;i--){
			sumright1+=GetTaste(i);
			if(sumright1>bigvalright1){
				bigvalright1=sumright1;
				bigvalrightID1=i;
			}
		}
		long long sumleft2=0LL;
		long long sumright2=0LL;
		long long bigvalleft2=0LL;
		long long bigvalright2=0LL;
		long long bigvalleftID2=0LL;
		long long bigvalrightID2=0LL;
		for( int i=0; i<bigvalrightID;i++){
			sumleft2+=GetTaste(i);
			//cout<<sumleft1<<endl;
			if(sumleft2>bigvalleft2){
				bigvalleft2=sumleft2;
				bigvalleftID2=i;
			}
		}
		for( int i=GetN()-1; i>=bigvalrightID;i--){
			sumright2+=GetTaste(i);
			if(sumright2>bigvalright2){
				bigvalright2=sumright2;
				bigvalrightID2=i;
			}
		}
		//cout<<bigvalleft1<<" "<<bigvalright1<<bigvalleft2<<" "<<bigvalright2<<endl;
		if(bigvalleft1+bigvalright1>bigvalleft2+bigvalright2){
			bigvalleft=bigvalleft1;
			bigvalright=bigvalright1;
		}
		else{
			bigvalleft=bigvalleft2;
			bigvalright=bigvalright2;
		}
	}
	cout<<bigvalleft+bigvalright;
	return 0;
}