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
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// PA2015TESTv2.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <set>
#include <stdio.h>
#include <iterator>
#include "kanapka.h"
#include "message.h"

using namespace std;
#define MAX 50000


//GetN();
//long long GetTaste(long long i);


int main()
{
	ios_base::sync_with_stdio(0);

	long long n = 0;
	//cin>>n;
	n = GetN();

	int *tastyArray = new int[n];
	for(int i = 0; i<n; i++)
	{
		tastyArray[i] = GetTaste(i);
	}

	/*tastyArray[0] = 10;
	tastyArray[1] = -2;
	tastyArray[2] = 5;
	tastyArray[3] = -4;
	tastyArray[4] = 3;
	tastyArray[5] = -5;
	tastyArray[6] = 1;*/

	long long max = 0;
	/*long long sumAll = 0;

	for (int i = 0; i < n; i++)
	{
		sumAll += tastyArray[i];
	}
	if(sumAll > max)
		max = sumAll;*/


	/*for (long long int i = 1 ; i < n + 1; i++)
	{
		for (long long int j = 0+  MyNodeId(); j < n-i; j+= NumberOfNodes())
		{
			long long tempSum = sumAll;
			for (long long int k = 0; k < i; k++)
			{
				tempSum -= tastyArray[j+k];
			}
			if(tempSum>max)
				max = tempSum;
		}
	}*/

	long long lewaSuma = 0;
	long long lewaMax = 0;
	long long lewaMaxInd = 0;



	for (long long int i = 0 ; i < n; i++)
	{
		lewaSuma += tastyArray[i];
		if(lewaSuma>lewaMax)
		{
			lewaMax = lewaSuma;
			lewaMaxInd = i;
		}
	}

	long long prawaSuma = 0;
	long long prawaMax = 0;
	long long prawaMaxInd = 0;

	for (long long int i = n-1 ; i > prawaMaxInd; i--)
	{
		prawaSuma += tastyArray[i];
		if(prawaSuma>prawaMax)
		{
			prawaMax = prawaSuma;
			prawaMaxInd = i;
		}
	}

	/*for (long long int i = 0 ; i < n; i++)
	{
		long long tempSum = sumAll;
		for (long long int j = i; j < n; j++)
		{
			tempSum -= tastyArray[j];
			if(tempSum>max)
				max = tempSum;
		}
	}*/

	/*for (long long int i = 1 ; i < n + 1; i++)
	{
		for (long long int j = 0; j < n-i; j++)
		{
			long long tempSum = sumAll;
			for (long long int k = 0; k < i; k++)
			{
				tempSum -= tastyArray[j+k];
			}
			if(tempSum>max)
				max = tempSum;
		}
	}*/




	/*  if (MyNodeId() > 0) {
    PutInt(0, max);
    Send(0);
  } else {
    for (int instancja = 1; instancja < NumberOfNodes(); ++instancja) {
      Receive(instancja);

	  long long ichmax = GetInt(instancja);
	  if(ichmax>max)
		  max = ichmax;
    }*/
	cout << prawaMax + lewaMax << endl;
  //}

	//cout<<max;
	cin>>n;
	return 0;
}