MINCARS Editorial

PROBLEM LINK:

Contest Division 1
Contest Division 2
Contest Division 3
Contest Division 4

Setter: Utkarsh Gupta
Tester: Abhinav Sharma, Nishank Suresh
Editorialist: Pratiyush Mishra

DIFFICULTY:

Cakewalk

PREREQUISITES:

None

PROBLEM:

A single car can accommodate at most 4 people.

N friends want to go to a restaurant for a party. Find the minimum number of cars required to accommodate all the friends.

EXPLANATION:

For each test case, we are given the number of friends going to the party.

Given 4 friends can use 1 car. Using this logic we can deduce that for N friends the minimum cars required will be:

  • 1, if N \le 4
  • (N/4), if N % 4=0
  • (N/4) + 1, if N % 4>0

TIME COMPLEXITY:

O(1) for each test case.

SOLUTION:

Editorialist's Solution
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    if(n<=4)
	    cout<<"1"<<"\n";
	   else if(n%4==0)
	    cout<<n/4<<"\n";
	    else if(n%4>0)
	    cout<<(n/4)+1<<"\n";
	    
	    
	}

Setter’s Solution
Tester-1’s Solution
Tester-2’s Solution