#include<cstdio> int min(int a, int b) { if (a > b) return b; else return a; } int main() { int n; scanf("%d", &n); unsigned long long sum = 0; int min_odd = 999999999; int odd_odd = 0; while (n--) { int a; scanf("%d", &a); if (a % 2 == 0) sum += a; else { min_odd = min(min_odd, a); if (odd_odd == 0) { odd_odd = a; } else { sum += odd_odd + a; odd_odd = 0; } } } if (odd_odd != 0) { sum += odd_odd - min_odd; } if (sum == 0) printf("NIESTETY\n"); else printf("%llu\n", sum); 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 | #include<cstdio> int min(int a, int b) { if (a > b) return b; else return a; } int main() { int n; scanf("%d", &n); unsigned long long sum = 0; int min_odd = 999999999; int odd_odd = 0; while (n--) { int a; scanf("%d", &a); if (a % 2 == 0) sum += a; else { min_odd = min(min_odd, a); if (odd_odd == 0) { odd_odd = a; } else { sum += odd_odd + a; odd_odd = 0; } } } if (odd_odd != 0) { sum += odd_odd - min_odd; } if (sum == 0) printf("NIESTETY\n"); else printf("%llu\n", sum); return 0; } |