Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official. ×

M.sayed97's blog

By M.sayed97, history, 2 years ago, In English,

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

 
 
 
 

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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);
}

}
  • »
    »
    2 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    thank you very much , i understand now what i did wrong . thank you a lot :D

  • »
    »
    10 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    can u plz write it in c?

    • »
      »
      »
      10 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it
      #include<bits/stdc++.h>
      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;i<n;i++){
      		scanf("%d",&a);
      		b[a]++;
      	}
      	ans+=b[4];
      	ans+=b[3];
      	if(b[1]>b[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);
      }
      
    • »
      »
      »
      10 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Although, you can see the tutorial/solution for almost all questions.

    • »
      »
      »
      10 months ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      Dear abirwaliullah98,

      The following is a GNU C++17 solution for the problem using C++11 lambda expressions.

      35443826

      Best wishes,

      • »
        »
        »
        »
        10 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        thanks a lot

        • »
          »
          »
          »
          »
          10 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          With pleasure.

        • »
          »
          »
          »
          »
          10 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          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