Chef in Fantasy League | CodeChef

#include<bits/stdc++.h>
#define Test int t;cin>>t;while(t–)
#define f(i,a,n) for(int i=a;i<n;i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define ll long long int
#define endl “\n”
using namespace std;

int main()
{
fastio;

Test
{
    int n,s;
    cin>>n>>s;
    
    std::vector<int> v(n) ;
    
    f(i,0,n)
    cin>>v[i];
    
    vector<int> f1(n);
    int min1=INT_MAX;
    int min2=INT_MAX;
    
    
    f(i,0,n)
    {
        cin>>f1[i];
        if(f1[i]==1)
        min1=min(min1,v[i]);
        else 
        min2=min(min2,v[i]);
    }
    
    ll x=min1+min2+s;
    if(x<=100)
    cout<<"yes"<<endl;
    else cout<<"no"<<endl;
}
return 0;

}

Whats wrong in this code?

Don’t use INT_MAX

1 Like

if f[i] is never 0 then min2 is INT_MAX. Now when you add them result is in int which causes overflow.
So, you got WA.

but the variable x which stores the total price of team has the data type of long long int.

Compiler executes the expression written on the RHS of = first a.k.a. r-value and as you can see each of them is of type int so the result castes into int which creates overflow, and then compiler assign the value to LHS a.k.a l-value.

is that even possible because we exactly need two more players one to be forward and one to be defender if there is no second player i.e all the player have value “1” i.e forward only the questions condition will not satisfy itself.
have a glance at the below code: CodeChef: Practical coding for everyone

Yeah then you have to print no. It is not written that there are 2 types of player present.

i guess you stay corrected.