#include <cstdio> using namespace std; typedef unsigned long long u64; u64 sum, a, b, x; bool ok = false; int main() { sum =0; a = 0; b = 0; int n; scanf("%d", &n); for(int i=0; i<n; ++i) { scanf("%llu", &x); if(x&1) { if(0 == a) { a = x; } else if(0 == b) { if(x > a) { b = a; a = x; } else { b = x; } } else { if(x >= b) { sum += x+a; a = b; ok = true; } else { sum += a + b; a = x; } b = 0; ok = true; } } else { sum += x; ok = true; } } if((a>0) && (b>0)) { sum += a+b; ok = true; } if(ok) printf("%llu\n", sum); else printf("NIESTETY\n"); 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 55 56 57 58 59 60 | #include <cstdio> using namespace std; typedef unsigned long long u64; u64 sum, a, b, x; bool ok = false; int main() { sum =0; a = 0; b = 0; int n; scanf("%d", &n); for(int i=0; i<n; ++i) { scanf("%llu", &x); if(x&1) { if(0 == a) { a = x; } else if(0 == b) { if(x > a) { b = a; a = x; } else { b = x; } } else { if(x >= b) { sum += x+a; a = b; ok = true; } else { sum += a + b; a = x; } b = 0; ok = true; } } else { sum += x; ok = true; } } if((a>0) && (b>0)) { sum += a+b; ok = true; } if(ok) printf("%llu\n", sum); else printf("NIESTETY\n"); return 0; } |