### M.sayed97's blog

By M.sayed97, history, 6 years ago,

the idea is when i find 4 I increase the number of taxis by one, and then i combine every 1's and 3's in one taxi, and i combine 2's with each other , and the remaining 2's and 1's i combine them and divide them by 4 and adds the result to number of taxis , if there is any remaining groups i increase the number of taxis by one . I get wrong answer at test case 64 and i don't know why so please any help . here is my submission code.............< 21109241 thanks in advance :D

• 0

| Write comment?
 » 6 years ago, # |   0 Check this modified code: import java.util.Scanner; public class copy { public static void main (String[]args){ Scanner sc = new Scanner(System.in); int number = sc.nextInt(); int taxis = 0; int []groups = new int [5]; for (int i = 0; i < number; i++) { groups[sc.nextInt()]++; } taxis +=groups[4]; taxis+=groups[2]/2; groups[2]=groups[2]%2; if (groups[3]!=0) { if (groups[3]>=groups[1]) { taxis+=groups[3]+groups[2]; } else { groups[1]-=groups[3]; taxis+=groups[3]; while(groups[2] > 0) { taxis++; groups[1] -=2; groups[2]--; } while(groups[1] > 0) { taxis++; groups[1] -=4; } } } else { while(groups[2] > 0) { taxis++; groups[1] -=2; groups[2] --; } while(groups[1] > 0) { taxis++; groups[1] -=4; } } System.out.println(taxis); } } 
•  » » 6 years ago, # ^ |   +1 thank you very much , i understand now what i did wrong . thank you a lot :D
•  » » 5 years ago, # ^ |   0 can u plz write it in c?
•  » » » 5 years ago, # ^ |   0 #include using namespace std; #define lli long long int //char a[2000][2000]; int main() { int n; cin>>n; int a,b[5]={0},ans=0,sum=0; for(int i=0;ib[3]) b[1]=b[1]-b[3]; else b[1]=0; sum=(b[1]+2*b[2]); if(sum%4!=0) ans+=1+(sum)/4; else ans+=(sum)/4; printf("%d",ans); } 
•  » » » 5 years ago, # ^ |   0 Although, you can see the tutorial/solution for almost all questions.
•  » » » 5 years ago, # ^ | ← Rev. 2 →   0 Dear abirwaliullah98,The following is a GNU C++17 solution for the problem using C++11 lambda expressions.35443826Best wishes,
•  » » » » 5 years ago, # ^ |   0 thanks a lot
•  » » » » » 5 years ago, # ^ |   0 With pleasure.
•  » » » » » 5 years ago, # ^ |   0 The following solution declares another lambda expression read_int in the main() function to read integers from cin. The return value of the lambda expression is used conveniently in the declaration statement of n, and as an index for the count array f. 35519772