### thelili018's blog

By thelili018, history, 4 years ago, , import java.util.Scanner;

public class Taxi2 {

public static void main (String[] args) {

int n, x, count;
int[] a;

Scanner sc = new Scanner(System.in);
n = sc.nextInt();
a = new int;

for(int i = 0; i < n; i++) {
x = sc.nextInt();
switch(x) {
case 1: a++; break;
case 2: a++; break;
case 3: a++; break;
case 4: a++; break;
}
}

count = a;

if(a != 0 && a != 0) {
x = (a >= a) ? a : a;
for(int i = 0; i < x; i++) {
a--;
a--;
count++;
}
}

count += a;
count += a / 2;
a = a % 2;

if(a != 0 && a >= 2) {
a--;
a = a - 2;
count++;
}
else
count += a;

count += a / 4;
if(a % 4 != 0)
count++;

System.out.println(count);
}


} 158b, taxi, java, Comments (6)
 » 4 years ago, # | ← Rev. 3 →   deleted
•  » » Is that why it fails on test 5? It's a time-complexity issue?
•  » » » 4 years ago, # ^ | ← Rev. 2 →   For test 5 answer is 1 but your code is giving output as 2. Test case 5 is22 1You can put both groups in one taxi so answer is one.
•  » » » » Thank you so much! That really helped!
•  » » You cannot solve it in O(1) just because you have to input N numbers...
 » import java.util.Scanner; import java.util.Arrays; public class Solution{ //what is wrong in this code ,this code is not working on testcase 37 where 3 values are given 3 3 2 // this code will produce 2 but the actual answer should be 3.(but how it can produce 3 beacuse there //are total 8 children so we can divide it into 4 and 4 ,so we need 2 taxies only and also we have to //return minimum no of taxies not maximum.) //please anyone can explain this `public static void main(String[] args){ Scanner s = new Scanner(System.in); int n = s.nextInt(); int a[] = new int[n]; int sum = 0; for(int i = 0;i