PROBLEM LINK:
Author: Gourav Rathor
Tester: Sumeet Pachauri
Editorialist: Gourav Rathor
Difficulty:
EASY
Prerequisites:
Basic looping, Basic maths
Problem:
You have given eating time (in seconds) A_1 to A_N of N customers.
You have to find minimum activity per second so that no customer have to wait for panipuri.
Where activity is ‘making a panipuri and putting it into the plate of customer’.
QUICK EXPLANATION:
we can find the minimum time taken to eat a panipuri. In this minimum time N have to be served to avoid waiting.
so our answer will be ceil(N/minimum_time).
Explanation:
Consider panipuri seller have N customers waiting for panipuri.
when he serve the customers, customer starts eating panipuri.
The seller must put next panipuri in customer’s plate before customer finishes his previous panipuri.
let the first customer take T_1 sec to consume panipuri so after putting panipuri in customer’s plate, seller have T_1 time to finish N activity, N-1 activity for other customers and 1 activity for the first customer so that he can get panipuri just after finishing the previous one.
let S is speed of seller,
so we can say that S \geq N / T_1.
similarly for 2_{nd} customer S \geq N / T_2.
.
.
similarly for i_{th} customer S \geq N/T_i.
.
.
similarly for N_{th} customer S \geq N/T_N.
so S should satisfy all above conditions.
let N/T_k is heighest among all N/T_i where 1 \leq i \leq N.
If S is greater than or equal to N/T_k, then S is also greater than or equal to all N/T_i, where 1 \leq i \leq N.
As we need to find minimum integral speed so, our answer will be S = ceil(N/T_k).
Now N/T_k to be heighest, T_k should be smallest.
So our task is to find minimum time taken to eat a panipuri, which is T_k.
Then print ceil(N/T_k).
Solution:
Setter's Solution
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
vector<int>v(n);
for(int i=0;i<n;i++)
cin>>v[i];
int min=v[0];
for(int i=1;i<n;i++) //finding minimum time to eat a panipuri
{
if(min>v[i])
min=v[i];
}
cout<<(int)ceil((float)n/min)<<"\n";
}
return 0;
}
Please give me suggestions if anything is unclear so that I can improve. Thanks