Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- int main(){
- int n;cin>>n;
- //turn into even and odd counts
- int oddCount=0,evenCount=0;
- for(int i=0;i<n;i++){
- int x;cin>>x;
- if(x%2==0)evenCount++;
- else oddCount++;
- }
- int ans=0;
- for(int i=0;i<=1001;i++){
- if(i%2==1){//need odd sum
- if(oddCount>=1){
- oddCount--;
- } else {
- break;
- }
- } else {//need even sum
- if(evenCount>=1){
- evenCount--;
- } else if(oddCount>=2){
- oddCount-=2;
- } else {
- break;
- }
- }
- ans++;
- }
- //(evenCount==0 and oddCount==1) or oddCount==0
- if(oddCount){
- cout<<ans-1<<endl;
- } else {
- cout<<ans<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement