Advertisement
ec1117

Untitled

Mar 6th, 2022
929
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     int n;cin>>n;
  7.  
  8.     //turn into even and odd counts
  9.     int oddCount=0,evenCount=0;
  10.     for(int i=0;i<n;i++){
  11.         int x;cin>>x;
  12.         if(x%2==0)evenCount++;
  13.         else oddCount++;
  14.     }
  15.  
  16.     int ans=0;
  17.     for(int i=0;i<=1001;i++){
  18.         if(i%2==1){//need odd sum
  19.             if(oddCount>=1){
  20.                 oddCount--;
  21.             } else {
  22.                 break;
  23.             }
  24.         } else {//need even sum
  25.             if(evenCount>=1){
  26.                 evenCount--;
  27.             } else if(oddCount>=2){
  28.                 oddCount-=2;
  29.             } else {
  30.                 break;
  31.             }
  32.         }
  33.         ans++;
  34.     }
  35.     //(evenCount==0 and oddCount==1) or oddCount==0
  36.     if(oddCount){
  37.         cout<<ans-1<<endl;
  38.     } else {
  39.         cout<<ans<<endl;
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement