/* Kieszonkowe [B] * Marek Iwaniuk * O(n) */ //#include "stdafx.h" #include <iostream> #include <cstdio> #include <algorithm> //#define scanf scanf_s #define INF 999999999 using namespace std; class Pocket { private: int n, in, vovel = 0, minimal = INF; long long res = 0, sum_of_vovel = 0; public: Pocket() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &in); if (in % 2 == 0) { res += (long long)in; } else { vovel++; sum_of_vovel += in; minimal = min(minimal, in); } } res += sum_of_vovel; if (vovel % 2 == 1) { res -= minimal; } } void Answer() { if (res == 0) { printf("NIESTETY\n"); } else { printf("%lld\n", res); } } }; int main() { Pocket *New = new Pocket(); New->Answer(); delete New; 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 42 43 44 45 46 47 48 49 50 51 52 53 54 | /* Kieszonkowe [B] * Marek Iwaniuk * O(n) */ //#include "stdafx.h" #include <iostream> #include <cstdio> #include <algorithm> //#define scanf scanf_s #define INF 999999999 using namespace std; class Pocket { private: int n, in, vovel = 0, minimal = INF; long long res = 0, sum_of_vovel = 0; public: Pocket() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &in); if (in % 2 == 0) { res += (long long)in; } else { vovel++; sum_of_vovel += in; minimal = min(minimal, in); } } res += sum_of_vovel; if (vovel % 2 == 1) { res -= minimal; } } void Answer() { if (res == 0) { printf("NIESTETY\n"); } else { printf("%lld\n", res); } } }; int main() { Pocket *New = new Pocket(); New->Answer(); delete New; return 0; } |