#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<string>
#include<queue>
unsigned long long nextTwoBankNotes(std::priority_queue<unsigned long>& q) {
unsigned long long result = 0L;
result += q.top();
q.pop();
result += q.top();
q.pop();
return result;
}
int main(int argc, char** argv)
{
std::ios_base::sync_with_stdio(false);
unsigned long n;
std::cin>>n;
unsigned long long money = 0L;
std::priority_queue<unsigned long> oddQueue;
unsigned long bankNote;
for(unsigned long long i = 0; i < n; ++i) {
std::cin>>bankNote;
if(bankNote % 2 == 0) {
money += bankNote;
} else {
oddQueue.push(bankNote);
if(oddQueue.size() == 3) {
money += nextTwoBankNotes(oddQueue);
}
}
}
while(oddQueue.size() >= 2) {
money += nextTwoBankNotes(oddQueue);
}
if(money > 0) {
std::cout<<money<<std::endl;
} else {
std::cout<<"NIESTETY"<<std::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 | #include<iostream> #include<vector> #include<algorithm> #include<cmath> #include<numeric> #include<string> #include<queue> unsigned long long nextTwoBankNotes(std::priority_queue<unsigned long>& q) { unsigned long long result = 0L; result += q.top(); q.pop(); result += q.top(); q.pop(); return result; } int main(int argc, char** argv) { std::ios_base::sync_with_stdio(false); unsigned long n; std::cin>>n; unsigned long long money = 0L; std::priority_queue<unsigned long> oddQueue; unsigned long bankNote; for(unsigned long long i = 0; i < n; ++i) { std::cin>>bankNote; if(bankNote % 2 == 0) { money += bankNote; } else { oddQueue.push(bankNote); if(oddQueue.size() == 3) { money += nextTwoBankNotes(oddQueue); } } } while(oddQueue.size() >= 2) { money += nextTwoBankNotes(oddQueue); } if(money > 0) { std::cout<<money<<std::endl; } else { std::cout<<"NIESTETY"<<std::endl; } return 0; } |
polski