https://www.codechef.com/problems/FFL

Why is my answer not being accepted?
#include
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
int n,s;
cin>>n;
cin>>s;
int price[n],role[n];
for(int i=0;i<n;i++)
cin>>price[i];
for(int i=0;i<n;i++)
cin>>role[i];
int mind=101,minl=101;
for(int i=0;i<n;i++)
{
if(role[i]==0)
{
if(mind>price[i])
mind=price[i];
}
if(role[i]==1)
{
if(minl>price[i])
minl=price[i];
}
}
if(mind!=101 && minl!=101)
{
int diff=100-(s+mind+minl);
if(diff<0)
cout<<“no”<<endl;
else
cout<<“yes”<<endl;
}

}
return 0;

}

for n=1 your code won’t print anything.
Check the constraints again.
Hope it helps!!

1 Like

#include
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
int n,s;
cin>>n;
cin>>s;
int price[n],role[n];
for(int i=0;i<n;i++)
cin>>price[i];
for(int i=0;i<n;i++)
cin>>role[i];
int mind=101,minl=101;
if(n!=1)
{
for(int i=0;i<n;i++)
{
if(role[i]==0)
{
if(mind>price[i])
mind=price[i];
}
if(role[i]==1)
{
if(minl>price[i])
minl=price[i];
}
}
if(mind!=101 && minl!=101)
{
int diff=100-(s+mind+minl);
if(diff<0)
cout<<“no”<<endl;
else
cout<<“yes”<<endl;
}
}
else
cout<<“no”<<endl;

}
return 0;

}
This code is still not working.I have added the n!=1 case also.

try for the case
n=2
s=25
25 30
1 1

Hope it helps!!

1 Like

This is because there may be condition when mind=101 and minl!=101. So, there is no else part for this if and you have to print no. Also, condition n!=1 was not needed.

1 Like