Skip to content

Instantly share code, notes, and snippets.

@maksadbek
Created July 16, 2014 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maksadbek/896f1ee20e6a74ee3c41 to your computer and use it in GitHub Desktop.
Save maksadbek/896f1ee20e6a74ee3c41 to your computer and use it in GitHub Desktop.
#include <iostream>
int taxi(int one, int two, int three, int four)
{
int cars = 0;
cars = four;
if((three - one) != 0)
{
cars += three - one;
three = (three % one);
}
else
{
cars += three;
one = one - three;
}
if(one > 1){
if((two - one/2) != 0)
{
cars += two - one/2;
two = two % one/2;
}
else
{
cars += two;
}
one = two;
}
else
{
cars += two / 2;
two = two % 2;
cars += two;
cars += one;
}
return cars;
}
int main()
{
int n;
int one=0, two=0, three=0, four=0;
std::cin>>n;
for(int i=0; i<n; i++)
{
int n;
std::cin>>n;
switch(n)
{
case 1:
one++;
break;
case 2:
two++;
break;
case 3:
three++;
break;
case 4:
four++;
default:
break;
}
}
int carsNeed = 0;
carsNeed = taxi(one,two,three,four);
std::cout<<carsNeed<<std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment