Menu Close

Find the number of days the expedition can last

Kalpana Chawla is planning an expedition to Jupiter for 𝑛 people. One of the important tasks is to provide biscuits for each participant.
The warehouse has π‘š daily biscuit packages. Each package has some biscuits type π‘Žπ‘–.

Each participant must eat exactly one biscuit package each day. Due to extreme loads, each participant must eat the same biscuit type throughout the expedition. Different participants may eat different (or the same) types of biscuits.

Formally, for each participant 𝑗 Kalpana Chawla should select the biscuit type 𝑏𝑗 and each day 𝑗-th participant will eat one biscuit package of type 𝑏𝑗. The values 𝑏𝑗 for different participants may be different.

Input:
The first line contains two integers 𝑛 and π‘š β€” the number of the expedition participants and the number of the daily biscuit packages available.

The second line contains a sequence of integers π‘Ž1,π‘Ž2,…,π‘Žπ‘š, where π‘Žπ‘– is the type of 𝑖-th biscuit package.

Output:
Print the output, the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0
#include<stdio.h>
#include<stdlib.h>
int cmpfunc(const void *a,const void *b){
 return(*(int*)b-*(int*)a);
}
int main()
{
   int a[101]={0},n,m,num,ans=0,i,day;
   scanf("%d %d",&n,&m);
   for(i=0;i<m;i++){
   scanf("%d",&num);
   a[num]++;
   }
   qsort(a,101,sizeof(int),cmpfunc);
   for( day=1;day<=100;day++){
   num=0;
   for(i=0;a[i]!=0;i++){
   num+=(a[i]/day);
   }
   if(num>=n)
   ans=day;
   }
   printf("%d",ans);
return 0;
}

INPUT_1:
4  8
2  1  1  1  2  5  7  2

OUTPUT:
1


INPUT_2:
2  5
5  4  3  2  1

OUTPUT:
1


ILLUSTRATION

Executed using gcc in linux terminal

Morae Q!