For the New Year's eve, you and your friends are going to fly sky lanterns ('Fanush') at the university campus. You have planned to do it at the night on January 14, 2021. Unfortunately, only one of your friends came to join. Another problem is that one cannot prepare the lantern alone and needs help from another person. So you two together will have to prepare each lanterns. After setting the fire, when one lantern starts to fly, you start to prepare another. You have bought a number of lanterns and they need different amount of times (bigger lanterns need more time) to start flying. As you are not allowed to stay for a long period, the university permitted you for a limited amount of time. You know the amount of time needed to fly for each lanterns. Your target is to fly as many sky lanterns as possible.
Determine the maximum number of lanterns that you will be able to fly.
Sample input:
2
7
3
1 4 9
100
3
150 200 101
Sample output:
2
Bad day!
Input Format
The first line contains an integer T, the number of test cases.
The first line of each test cases will contain an integer t, the allowed time in minutes.
The second line of the test case will contain an integer n, the number of sky lanterns.
Then the following line will contain a sequence of n numbers a1, a2 ... an where ai denotes the amount of time (in minute) needed to fly for i-th lantern.
Constraints
t>=0 and t<=1000
n>0
ai>=0
Output Format
For each test case, print a single integer N which denotes the maximum number of lanterns that you will be able to fly.
If you are unable to fly any lantern within the alotted time, then print "Bad day!".
Sample Input 0
2
7
3
1 4 9
100
3
150 200 101
Sample Output 0
2
Bad day!
#include<iostream>
using namespace std;
int main(){
int minutes=0,r;
int timeframe=100; // timeframe to make all lanterns;
int numberoflanterns; // The number of lanterns to make
cout<<"Enter number of lanterns you want to make"<<endl;
cin>>numberoflanterns;
for(int i=1;i<=numberoflanterns;++i){
cout<<"Enter time in minutes needed to make LANTERN"<<i<<" .Time should not be lessthan 20minutes"<<endl;
cin>>r;
minutes=minutes+r;
}
if(minutes>timeframe){
cout<<"BAD DAY"<<endl;
}else{
cout<<"Number of lanterns="<<numberoflanterns<<endl;
}
return 0;
}
Comments
Leave a comment