#include <stdio.h>
int main()
{
int n;
int ai;
int cash[1001] = { 0 };
scanf("%d", &n);
for (int i = 0; i < n; ++i)
{
scanf("%d", &ai);
++cash[ai];
}
int lastOdd = 0;
unsigned int total = 0;
for (int i = 1000; i > 0; --i)
{
while (cash[i] > 0)
{
if (i % 2 == 1)
{
if (lastOdd != 0)
{
total += i + lastOdd;
lastOdd = 0;
}
else
{
lastOdd = i;
}
}
else
{
total += i;
}
--cash[i];
}
}
if (total > 0)
printf("%u", total);
else
printf("NIESTETY");
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 | #include <stdio.h> int main() { int n; int ai; int cash[1001] = { 0 }; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &ai); ++cash[ai]; } int lastOdd = 0; unsigned int total = 0; for (int i = 1000; i > 0; --i) { while (cash[i] > 0) { if (i % 2 == 1) { if (lastOdd != 0) { total += i + lastOdd; lastOdd = 0; } else { lastOdd = i; } } else { total += i; } --cash[i]; } } if (total > 0) printf("%u", total); else printf("NIESTETY"); return 0; } |
English