### M.sayed97's blog

By M.sayed97, history, 5 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

 » 5 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); } } 
•  » » 5 years ago, # ^ |   +1 thank you very much , i understand now what i did wrong . thank you a lot :D
•  » » 4 years ago, # ^ |   0 can u plz write it in c?
•  » » » 4 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); } 
•  » » » 4 years ago, # ^ |   0 Although, you can see the tutorial/solution for almost all questions.
•  » » » 4 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,
•  » » » » 4 years ago, # ^ |   0 thanks a lot
•  » » » » » 4 years ago, # ^ |   0 With pleasure.
•  » » » » » 4 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
»
2 years ago, # |
-8

Whats wrong with this code?

# include<bits/stdc++.h>

using namespace std;

int main() {

long arr[100000],n,sum=0,res=0;

cin>>n;

for(int i=0;i<n;i++){
cin >> arr[i];
}

for(int i=0;i<n;i++){
sum+=arr[i];
}
res=sum/4;

if(sum%4==0){
cout<<res;
}
else{
cout<<res+1;
}

}

•  » » 2 years ago, # ^ |   0 same problem here also would like to help from u if u got it the solution
•  » » 23 months ago, # ^ |   0 take the test cases like 3 3 2 the output should be 3 but by your code it will be 2.
•  » » 22 months ago, # ^ |   0 Same problem with my code package Codeforce;import java.util.Scanner;public class Taxi { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr[]=new int[n]; int sum=0; int taxi=0; int seatleft=0; for(int i=0;i=4) { ++taxi; sum-=4; } } System.out.println(taxi); } }//2 3 4 4 2 1 3 1 // 12433 // 3 3 2 /* * * if(arr[i]%4==0) { taxi++; } else if(arr[i]<4) {  if(seatleft==0) { taxi++; seatleft=4-arr[i]; System.out.println("Seatleft 0"+ arr[i]); System.out.println(seatleft); } else if(seatleft!=0) { seatleft+=arr[i]; taxi++; seatleft-=4; } }*/ 
 » 2 months ago, # |   0 x = int(input()) i = 0 t = 0 z = 0for i in range(x): t = int(input()) z = z+t i = i+1k = z // 4 p = z % 4if p == 0: print(k) else: k = k + 1 print(k)