#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template<typename TH>
void debug_vars(const char* data, TH head){
cerr << data << "=" << head << "\n";
}
template<typename TH, typename... TA>
void debug_vars(const char* data, TH head, TA... tail){
while(*data != ',') cerr << *data++;
cerr << "=" << head << ",";
debug_vars(data+1, tail...);
}
#ifdef LOCAL
#define debug(...) debug_vars(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#endif
/////////////////////////////////////////////////////////
int N;
int total, minOdd;
bool anyOdd;
void input(){
anyOdd = false;
total = 0;
minOdd = numeric_limits<int>::max();
scanf("%d", &N);
for(int i = 0; i < N; i++){
int v;
scanf("%d", &v);
total += v;
if(v % 2 == 1){
minOdd = min(minOdd, v);
anyOdd = true;
}
}
}
int main(){
input();
if(total % 2 == 0){
printf("%d\n", total);
} else if(N > 1){
assert(anyOdd);
printf("%d\n", total - minOdd);
} else {
printf("NIESTETY\n");
}
}
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 <bits/stdc++.h> using namespace std; typedef long long LL; template<typename TH> void debug_vars(const char* data, TH head){ cerr << data << "=" << head << "\n"; } template<typename TH, typename... TA> void debug_vars(const char* data, TH head, TA... tail){ while(*data != ',') cerr << *data++; cerr << "=" << head << ","; debug_vars(data+1, tail...); } #ifdef LOCAL #define debug(...) debug_vars(#__VA_ARGS__, __VA_ARGS__) #else #define debug(...) (__VA_ARGS__) #endif ///////////////////////////////////////////////////////// int N; int total, minOdd; bool anyOdd; void input(){ anyOdd = false; total = 0; minOdd = numeric_limits<int>::max(); scanf("%d", &N); for(int i = 0; i < N; i++){ int v; scanf("%d", &v); total += v; if(v % 2 == 1){ minOdd = min(minOdd, v); anyOdd = true; } } } int main(){ input(); if(total % 2 == 0){ printf("%d\n", total); } else if(N > 1){ assert(anyOdd); printf("%d\n", total - minOdd); } else { printf("NIESTETY\n"); } } |
English