#include <iostream> #include <algorithm> #define N_MAX 1000000 #define INF 10000 using namespace std; int n; short a[N_MAX]; long long sum; short min_elem = INF; // minimalny nieparzysty int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; sum += a[i]; if ((a[i] % 2 == 1) && (a[i] < min_elem)) min_elem = a[i]; } if (sum % 2 == 0) cout << sum; else // sum - nieparzyste { if (n == 1) { cout << "NIESTETY"; } else // n > 1 { cout << sum - min_elem; } } 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 | #include <iostream> #include <algorithm> #define N_MAX 1000000 #define INF 10000 using namespace std; int n; short a[N_MAX]; long long sum; short min_elem = INF; // minimalny nieparzysty int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; sum += a[i]; if ((a[i] % 2 == 1) && (a[i] < min_elem)) min_elem = a[i]; } if (sum % 2 == 0) cout << sum; else // sum - nieparzyste { if (n == 1) { cout << "NIESTETY"; } else // n > 1 { cout << sum - min_elem; } } return 0; } |