Any integer value greater than 100. I’ve used 500 and it’s working fine.
ok ,thanks
#include
using namespace std;
int main(){
int t;
cin>>t;
while(t–){
int n,s;
cin>>n>>s;
int p[2][n];
for(int i=0;i<n;i++){
cin>>p[0][i];
}
for(int j=0;j<n;j++){
cin>>p[1][j];
}
int su=0;
int am=100-s;
if(n==1){
cout<<"no"<<endl;
}
else{
for(int k=0;k<n;k++){
for(int l=k+1;l<n;l++){
if((p[0][k]+p[0][l])<=am){
if(p[1][k]+p[1][l]==1){
su=su+1;
cout<<"yes"<<endl;
break;
}
}
}
}
if(su==0){
cout<<"no"<<endl;
}
}
}
return 0;
}
this code gives me wrong answer. please help.
It’s O(n) because, if you have two loops it’s actually O(n + n) => O(2n) which is constant. So it can be written as O(2n) => O(n).
Hope it helps.
Ohh yess !! Gotcha
Begin() and end() returns pointer so use *d.begin() and *f.begin() to use the value.
Format your code and while doing that refer to the following guidelines:
Yes I did. I don’t know why it’s not visible here. Though I included that
#include<iostream>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n,s;
cin>>n>>s;
int p[2][n];
for(int i=0;i<n;i++){
cin>>p[0][i];
}
for(int j=0;j<n;j++){
cin>>p[1][j];
}
int su=0;
int am=100-s;
if(n==1){
cout<<"no"<<endl;
}
else{
for(int k=0;k<n;k++){
for(int l=k+1;l<n;l++){
if((p[0][k]+p[0][l])<=am){
if(p[1][k]+p[1][l]==1){
su=su+1;
cout<<"yes"<<endl;
break;
}
}
}
}
if(su==0){
cout<<"no"<<endl;
}
}
}
return 0;
}
#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