Chef in Fantasy League - FFL (April Lunch Time CodeChef Question)
Hello Everyone , Welcome back to my blog .
Today we will be discussing the latest Codechef's question of April Lunch Time which concluded just now :-
Here is the Problem
Today we will be discussing the latest Codechef's question of April Lunch Time which concluded just now :-
Here is the Problem
Chef is going to start playing Fantasy Football League (FFL) this season. In FFL, each team consists of exactly players: goalkeepers, defenders, midfielders and forwards. Chef has already bought players; he is only missing one defender and one forward.
There are available players (numbered through ). For each valid , the -th player is either a defender or a forward and has a price . The sum of prices of all players in a team must not exceed dollars and the players Chef bought already cost him dollars.
Can you help Chef determine if he can complete the team by buying one defender and one forward in such a way that he does not exceed the total price limit?
Input
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains two space-separated integers and .
- The second line contains space-separated integers .
- The last line contains space-separated integers. For each valid , the -th of these integers is if the -th player is a defender or if the -th player is a forward.
Output
For each test case, print a single line containing the string
"yes"
if it is possible to build a complete team or "no"
otherwise (without quotes).Constraints
- for each valid
Subtasks
Subtask #1 (100 points): original constraints
Example Input
2
4 90
3 8 6 5
0 1 1 0
4 90
5 7 6 5
0 1 1 0
Example Output
yes
no
Explanation
Example case 1: If Chef buys the -st and -rd player, the total price of his team is , which is perfectly fine. There is no other valid way to pick two players.
Example case 2: Chef cannot buy two players in such a way that all conditions are satisfied.
SOLUTION
I guess the answer is fairly simple , calculate the amount of money Chef can spend more which is equal to 100-s and then just find the minimum price of a defender and of a forward.
If their sum is less than or equal to 100-s simply print yes otherwise no.
Here is the C++ Code :-
#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int n,s;
cin>>n;
cin>>s;
s=100-s;
int arr[n],arr1[n];
int i=0;
while(i!=n)
{
cin>>arr[i];
i++;
}
i=0;
while(i!=n)
{
cin>>arr1[i];
i++;
}
int min=500,min1=500;
i=0;
while(i!=n)
{
if(arr1[i]==0)
{
if(arr[i]<min1)
{
min1=arr[i];
}
}
if(arr1[i]==1)
{
if(arr[i]<min)
{
min=arr[i];
}
}
i++;
}
if(min+min1<=s)
{
cout<<"yes"<<endl;
}
else
{
cout<<"no"<<endl;
}
}
// your code goes here
return 0;
}
Comments
Post a Comment