Created
January 4, 2016 16:16
-
-
Save Jack-Saleem/0f1b58bb451a4d64d81b to your computer and use it in GitHub Desktop.
Codeforces 158B Taxi program in java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Taxi | |
{ | |
public static void main(String args[]) | |
{ | |
Scanner ip = new Scanner(System.in); | |
int a = ip.nextInt(); | |
int c1=0,g2=0,g3=0,c4=0,b,c,d; | |
int[] x = new int[a]; | |
for(int i=0;i<x.length;i++) | |
{ | |
x[i]=ip.nextInt(); | |
if(x[i]==1) | |
c1++; | |
else if(x[i]==2) | |
g2++; | |
else if(x[i]==3) | |
g3++; | |
else | |
c4++; | |
} | |
if(g3>c1) | |
{ | |
b=g3-c1; | |
if(g2%2==0) | |
System.out.println(c4+(g3-b)+b+(g2/2)); | |
else | |
System.out.println(c4+(g3-b)+b+(g2/2)+1); | |
} | |
else if(g3<c1 && g2%2==0) | |
{ | |
c=c1-g3; | |
if((c%4)==0) | |
System.out.println(c4+(c1-c)+(g2/2)+(c/4)); | |
else | |
System.out.println(c4+(c1-c)+(g2/2)+(c/4)+1); | |
} | |
else if(g3<c1 && g2%2!=0) | |
{ | |
d=c1-g3; | |
if((d%4)<=2) | |
System.out.println(c4+(c1-d)+(g2/2)+(d/4)+1); | |
else if((d%4)==0) | |
System.out.println(c4+(c1-d)+(g2/2)+(d/4)+1); | |
else | |
System.out.println(c4+(c1-d)+(g2/2)+(d/4)+2); | |
} | |
else | |
{ | |
if(g2%2==0) | |
System.out.println(c4+g3+(g2/2)); | |
else | |
System.out.println(c4+g3+(g2/2)+1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment