FFL - Editorial

#include<bits/stdc++.h>
using namespace std;
#define ll long long int

ll n,mdf=101,a,b,s,fd=101,tc=0;

int main(){

vectorcost(n);
vectorpos(n);

cin>>tc;
while(tc--){
  cin>>n>>s;
  for(ll i=0;i<n;i++){
    cin>>a;
    cost.push_back(a);
  }
 for(int i=0;i<n;i++){
    cin>>b;
    pos.push_back(b);
  } 
   if(cost.size()==0 || pos.size()==0 ){
   cout<<"no"<<endl;
   exit(1);
  }
 for(ll i=0;i<n;i++){
      if(pos[i])
      mdf=min(mdf,cost[i]);
      else
      fd=min(fd,cost[i]);
  }
if(mdf+fd<=100-s)
  cout<<"yes"<<endl;
  else cout<<"no"<<endl ; 
       } 

return 0;
}
//i am getting wrong answer for this but not when custom input provided…please someone help

@sonaliagrawal Did you run your program on different test-cases other than the given test-cases?

Because your program is giving multiple outputs for the given case?

1
5 87
4 2 3 1 2
1 0 1 0 1

Your Code Output:

yes
yes
yes
yes

Correct Output:

yes

@sonaliagrawal After making changes in your code, run your code on the following test-cases, if it gives correct output then you can claim that your code is correct.

5
4 90
3 8 6 5
0 1 1 0
4 90
5 7 6 5
0 1 1 0
5 87
4 2 3 1 2
1 0 1 0 1
1 100
2
1
1 85
7
0

Correct-Output:

yes
no
yes
no
no

Oh okay, got it thanks a lot.

Could anyone please suggest me why it’s not passing

what is the problem with this code
#include
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
int t;
cin>>t;
while(t–)
{
int n,s;
cin>>n>>s;
int cost[n],defe[n],sum=0;
for(int i=0;i<n;i++)
{
cin>>cost[i];
}
for(int i=0;i<n;i++)
{
cin>>defe[i];
if(defe[i]==0)
count1++;
else
count2++;
}

	for(int i=0;i<n-1;i++)
	{
		for(int j=0;j<n-i-1;j++)
		{
			if(cost[j]>cost[j+1])
			{
				int temp1=cost[j];
				cost[j]=cost[j+1];
				cost[j+1]=temp;
				
				int temp2=defe[j];
				defe[j]=defe[j+1];
				defe[j+1]=temp;
			}
		}
	}
	if(n=1)
		cout<<"NO"<<endl;
	else if(count1==0 || count2==0)
		cout<<"NO"<<endl;
	else
	{
		sum=sum+cost[0];
		if(sum>(100-s))
			cout<<"NO"<<endl;
		else
		{
			for(int i=0;i<n;i++)
			{
				if(defe[i]=1)
				{
					sum=sum+cost[i];
					break;
				}
			}
		if(sum<=(100-s))
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
		}
	}
	
	
	
}
return 0;

}

#include <stdio.h>
#include <stdlib.h>
int it,i,j,k,p[20],c[20],in,is,iv=0;
int main(void)
{
// printf(“no. of testcases: “);
scanf(”%d”,&it);
for(i=0;i<it;i++)
{
// printf(“enter no. of player available and total money used:\n”);
scanf("%d%d",&in,&is);
// printf(“enter the price of players:\n”);
for(j=0;j<in;j++)
{
scanf("%d",&p[j]);
}
// printf(“enter 0(defender) and 1(forward):\n”);
for(j=0;j<in;j++)
{
scanf("%d",&c[j]);
}
for(j=0;j<in;j++)
{
for(k=j+1;k<in;k++)
{
if(c[j]==0)
{
if(c[k]==1)
{
if(p[j]+p[k]<(100-is))
{
iv=1;
break;
}
}
}
else
{
if(c[k]==0)
{
if(p[j]+p[k]<(100-is))
{
iv=1;
break;
}
}
}
}
}
if(iv==1)
{
printf(“yes”);
}
else
{
printf(“no”);
}
printf("\n");
iv=0;
}
return 0;

}

whats the problem in this code
when submitted its showing wrong answer
but the output is coming correct

Firstly, Format your code

I don’t see this line in the sample output. You need to print exactly as specified in the output section of the question.

#include
using namespace std;
int main(){
int n,s,t;

cin>>t;
bool *flag= new bool[t];
for(int i=0;i<t;i++)
{
flag[i]=false;
}
int i=0;
while(i< t)
{

cin>>n>>s;
int temp1,temp2;
int available=100-s;
int *arr=new int[n];
int *p=new int [n];
for(int j=0;j<n;j++)
{
  cin>>p[j];
}
for(int j=0;j<n;j++)
{
   cin>>arr[j];
}
for(int j=0;j<n;j++)
{
  if(arr[j]==0)
  {

      for(int k=j+1;k<n;k++)
      {
         if(arr[k]==1)
         {
             if(p[j]+p[k]<available)
             {
                flag[i]=true;
                break;
             }
             else
                flag[i]=false;
         }

      }
  }
}

i++;
}
for(int i=0;i<t;i++)
{
if(flag[i])
{
cout<<“yes”<<endl;
}
else
{
cout<<“no”<<endl;
}
}

}

There is a mistake in the editorial, in the last formula,
It must be: min_D+min_F \leq 100-S and not min_D+min_D \leq 100-S

bro i have commented that line it will not print anything

I don’t understand why I am getting wrong answer for this. Can somebody please help?

#include <bits/stdc++.h>
using namespace std;

int main() {
int t; int n; int s; int curr; int f_min; int d_min;
cin >> t;

while(t>0) {
	cin >> n >> s;
	if(n <= 1) {
		cout << "no" << endl;
		t--;
		continue;
	}
	int P[n];
	f_min = INT_MAX;
	d_min = INT_MAX;

	for(int i=0; i<n; i++) {
		cin >> P[i];
	}
	for(int i=0; i<n; i++) {
		cin >> curr;
		if(curr == 0 && P[i] < d_min) {
			d_min = P[i];
		}
		else if(curr == 1 && P[i] < f_min) {
			f_min = P[i];
		}
	}

	if(d_min + f_min + s <= 100) {
		cout << "yes" << endl;
	}
	else {
		cout << "no" << endl;
	}

	t--;
}
return 0;
}

1
4 90
3 8 6 5
1 1 1 1
your code is getting wrong for above case .If they given only one type of player .then your code should give “no”. but it is giving yes.

If they only give one type of player then either of f_min or d_min should remain INT_MAX. So shouldn’t the final sum remain greater than 100?

But according to the question you have to select both players .The final sum should not be greater than 100.

I understand how INT_MAX fails, since if either of f_min or d_min is equal to INT_MAX, then the sum d_min + f_min + s would overflow.

However, say I initialize f_min and d_min to 1000 each, the test case you suggested produces the correct answer. Shouldn’t the code work fine?

Don’t take pressure my son.

for j in range(int(input())):

N,S= map(int,input().split())

L=list(map(int,input().split()))

i=list(map(int,input().split()))

p=[]

q=[]

if 0 not in i or 1 not in i:

    print("no")

else:

    for j in range(N):

        if i[j]==0:

            p.append(L[j])

        else:

            q.append(L[j])

    total=S+min(p)+min(q)

    if total<=100:

        print("yes")

    else:

        print("No")

What is wrong with this code? Showing runtime error.

Some one please explain why am i getting runtime error after getting correct answer in every possible case…
https://www.codechef.com/viewsolution/37212975

Why is it showing run time error?
T=int(input())
for i in range(T):
N,S=map(int,input().split())
P=list(map(int,input().split()))[:N]
L=list(map(int,input().split()))[:N]
A=[]
B=[]
for j in range(len(L)):
if L[j]==0:
A.append(P[j])
elif L[j]==1:
B.append(P[j])
Sum=(min(A)+min(B))
if len(A)!=0 and len(B)!=0:
if Sum<=100-S:
print(“yes”)
else:
print(“no”)
else:
print(“no”)