// Potyczki Algorytmiczne 2015
// runda 1
// KIEszonkowe
// Tomasz Pastusiak
// version without log n sort
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main(){
ios_base::sync_with_stdio(false); // what is the difference?
int n, tmp, oddsCount, usedBillsSum;
cin >> n;
int oddBills[n];
oddsCount = 0;
usedBillsSum = 0;
for(int i=0;i<n;++i){
cin >> tmp;
if(tmp%2){
oddBills[oddsCount++] = tmp;
}
else{
usedBillsSum += tmp; // do not save evens, they always can be split in half so just use them
}
}
// lets take even ammount of odd bills, so the sum will still be even. (odd+odd=even)
// we'll just take all of them, and remove the smallest one if needed
for(int i=0;i<oddsCount;++i){
usedBillsSum += oddBills[i];
}
if(oddsCount%2){
int smallest = 1001; // the biggest bill is 1000....
for(int i=0;i<oddsCount;++i){
smallest = min(smallest, oddBills[i]);
}
usedBillsSum -= smallest;
} // if we have to remove one, the smallest one
if(usedBillsSum == 0){
cout << "NIESTETY" << endl;
}
else{
cout << usedBillsSum << endl;
}
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 | // Potyczki Algorytmiczne 2015 // runda 1 // KIEszonkowe // Tomasz Pastusiak // version without log n sort #include <iostream> #include <algorithm> #include <functional> using namespace std; int main(){ ios_base::sync_with_stdio(false); // what is the difference? int n, tmp, oddsCount, usedBillsSum; cin >> n; int oddBills[n]; oddsCount = 0; usedBillsSum = 0; for(int i=0;i<n;++i){ cin >> tmp; if(tmp%2){ oddBills[oddsCount++] = tmp; } else{ usedBillsSum += tmp; // do not save evens, they always can be split in half so just use them } } // lets take even ammount of odd bills, so the sum will still be even. (odd+odd=even) // we'll just take all of them, and remove the smallest one if needed for(int i=0;i<oddsCount;++i){ usedBillsSum += oddBills[i]; } if(oddsCount%2){ int smallest = 1001; // the biggest bill is 1000.... for(int i=0;i<oddsCount;++i){ smallest = min(smallest, oddBills[i]); } usedBillsSum -= smallest; } // if we have to remove one, the smallest one if(usedBillsSum == 0){ cout << "NIESTETY" << endl; } else{ cout << usedBillsSum << endl; } return 0; } |
English