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

Chef is going to start playing Fantasy Football League (FFL) this season. In FFL, each team consists of exactly 15 players: 2 goalkeepers5 defenders5 midfielders and 3 forwards. Chef has already bought 13 players; he is only missing one defender and one forward.
There are N available players (numbered 1 through N). For each valid i, the i-th player is either a defender or a forward and has a price Pi. The sum of prices of all players in a team must not exceed 100 dollars and the players Chef bought already cost him S 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 T denoting the number of test cases. The description of T test cases follows.
  • The first line of each test case contains two space-separated integers N and S.
  • The second line contains N space-separated integers P1,P2,,PN.
  • The last line contains N space-separated integers. For each valid i, the i-th of these integers is 0 if the i-th player is a defender or 1 if the i-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

  • 1T100
  • 1N100
  • 13S100
  • 1Pi100 for each valid i

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 1-st and 3-rd player, the total price of his team is 90+9=99, 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

Popular Posts