899A - Splitting in Teams - CodeForces Solution


constructive algorithms greedy math *800

Please click on ads to support us..

Python Code:

import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

n = int(input())
a = list(map(int, input().split()))
u, v = 0, 0
for i in a:
    if i % 2:
        u += 1
    else:
        v += 1
m = min(u, v)
u, v = u - m, v - m
ans = m + u // 3
print(ans)

C++ Code:

/**بِسْمِ ٱللَّهِ ٱلرَّحْمَـٰنِ ٱلرَّحِيمِ */
/** المؤلف: محفوظ الرحمن */


#include<bits/stdc++.h>
using namespace std;

/** Loop */
#define lpi(n) for(int i=0;i<n;i++)
#define lpi1(n) for(int i=1;i<n;i++)
#define lpj(m) for(int j=0;j<m;j++)
#define lpr(m) for(int j=m-1;j>=0;j--)



/** Array  */
#define ar_mne(v,n) *min_element(v,v+n)
#define ar_mxe(v,n) *max_element(v,v+n)
#define sz(ar) sizeof(ar)/sizeof(ar[0])
#define a_cnt(v,n,a) count(v,v+n,a)



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

   int n;
   cin>>n;
   int ar[n];
   lpi(n) cin>>ar[i];
   int one = a_cnt(ar,n,1);
   int two = a_cnt(ar,n,2);
   int ans = 0;
   if(one>two)
   {
       ans = two + (one - two)/3;
   }
   else
   {
       ans = one ;
   }
   cout<<ans<<endl;




    return 0;

}



Comments

Submit
0 Comments
More Questions

Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making