#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int N; vector<long long> numbers; cin >> N; for (int i = 0; i < N; i++) { long long v; cin >> v; numbers.push_back(v); } sort(numbers.begin(), numbers.end()); long long last_uneven = 0; long long sum = 0; for (int j = numbers.size() - 1; j >= 0; j--) { sum += numbers[j]; if (numbers[j] % 2 == 1) { last_uneven = numbers[j]; } } if (sum % 2 == 1) { sum -= last_uneven; } if (sum > 0) { cout << sum << endl; } else { cout << "NIESTETY" << endl; } 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int N; vector<long long> numbers; cin >> N; for (int i = 0; i < N; i++) { long long v; cin >> v; numbers.push_back(v); } sort(numbers.begin(), numbers.end()); long long last_uneven = 0; long long sum = 0; for (int j = numbers.size() - 1; j >= 0; j--) { sum += numbers[j]; if (numbers[j] % 2 == 1) { last_uneven = numbers[j]; } } if (sum % 2 == 1) { sum -= last_uneven; } if (sum > 0) { cout << sum << endl; } else { cout << "NIESTETY" << endl; } return 0; } |