#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int best0 = 0, best1 = 0;
while (n--) {
int l;
scanf("%d", &l);
if (l % 2 == 0) {
best0 += l;
if (best1 != 0) best1 += l;
} else {
int s0 = best0, s1 = best1;
best1 = max(s1, s0 + l);
if (s1 != 0) best0 = max(s0, s1 + l);
}
}
if (best0 == 0) puts("NIESTETY");
else printf("%d\n", best0);
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 | #include <iostream> #include <stdio.h> using namespace std; int main() { int n; scanf("%d", &n); int best0 = 0, best1 = 0; while (n--) { int l; scanf("%d", &l); if (l % 2 == 0) { best0 += l; if (best1 != 0) best1 += l; } else { int s0 = best0, s1 = best1; best1 = max(s1, s0 + l); if (s1 != 0) best0 = max(s0, s1 + l); } } if (best0 == 0) puts("NIESTETY"); else printf("%d\n", best0); return 0; } |
English