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

using namespace std;

const int MAX_NOM = 1000;
const int MAX_N = 1000000;
unsigned smallest_remaining_nominal;

// wczytuje dane z wejscia i wypelnia tablice nominals
// zwraca sume wartosci wszystkich podanych banknotow
unsigned init() {
	smallest_remaining_nominal = MAX_N * MAX_NOM +1;
	unsigned n; // liczba banknotow
	unsigned suma = 0; // suma wartosci banknotow
	cin >> n;
	unsigned value;
	for (unsigned i = 0; i < n; i++) {
		cin >> value;
		suma += value;
		if (value % 2 == 1 && value < smallest_remaining_nominal)
			smallest_remaining_nominal = value;
	}
	return suma;
}

// wypisuje wynik
void printResult(int result) {
	if (result == 0) {
		cout << "NIESTETY";
	} else {
		cout << result;
	}
}

int main() {
	unsigned result = init();
	unsigned nominal = 1;

	if (result % 2 == 1) { // jesli result%2==0 to result jest maksymalny mozliwy
		result--; // result to liczba parzysta
		// idziemy od mozliwie jak najwiekszej kwoty w dol
		while (result > 0) {
			if (smallest_remaining_nominal == nominal)
				break;
			result -= 2;
			nominal += 2;
		}
	}
	printResult(result);
	return 0;
}