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
#include <iostream>

int dziel(int x, int y[], int z);
int main(int argc, char** argv) {
	int rozmiar,wynik;

	std::cin >> rozmiar;
	int *y = new int[rozmiar];
	for (int i=0;i<rozmiar;i++)
		std::cin >> y[i];
	wynik=dziel(rozmiar,y,-1);
	if (wynik!= -1)
		std:: cout << wynik << std::endl;
	else
		std:: cout << "NIESTETY\n";
	
	
	delete []y;
	return 0;
}


int dziel(int x, int y[],int z)
{
	int suma=0;
	int n=-1,a,b,c;
	if (z>=0)
	{
		a=y[z];
		b=y[x-1];
		y[z]=b;
		y[x-1]=a;
	}
	for (int i=0;i<x;i++)
	suma=suma+y[i];


	if (suma%2 && x>1)
	{ 
		for (int i=0;i<x;i++)
		{
			c=dziel(x-1,y,i);
			if (n<c)
				n=c;
		}
		suma=n;
	}
	else if (suma%2==0)
		return suma;
	if (x<=1)
		return -1;

	
}