#include <cstdio> long long res = 0; int n, l, np[3], count = 0; void add() { np[count] = l; for (int i = count; i > 0; ++i) { if (np[i] > np[i-1]) { int t = np[i]; np[i] = np[i-1]; np[i-1] = t; } else break; } ++count; if (count == 3) { res += np[0] + np[1]; np[0] = np[2]; count = 1; } } int main(int argc, const char * argv[]){ scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &l); if (l % 2 > 0) add(); else res += l; } if (count == 2) res += np[0] + np[1]; if (res == 0) printf("NIESTETY"); else printf("%lld", res); 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 | #include <cstdio> long long res = 0; int n, l, np[3], count = 0; void add() { np[count] = l; for (int i = count; i > 0; ++i) { if (np[i] > np[i-1]) { int t = np[i]; np[i] = np[i-1]; np[i-1] = t; } else break; } ++count; if (count == 3) { res += np[0] + np[1]; np[0] = np[2]; count = 1; } } int main(int argc, const char * argv[]){ scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &l); if (l % 2 > 0) add(); else res += l; } if (count == 2) res += np[0] + np[1]; if (res == 0) printf("NIESTETY"); else printf("%lld", res); return 0; } |