rescue-wrong answer

Can anyone say that what is my wrong
problem is Rescue and this my code

@shikimaru : Here is the answer to your question on problem page , together with a bug in your submission program .
s = 3 : Take 2 child and 1 man , since priority of child is greater than women . s = 5 : Take 4 child and 1 man , same reason . Regarding your submission code : I didn’t take pains to understand your logic completely . But atleast I have figured out the first place where error occurs . while(!((c+3)/4<=3*m && c+(c+3)/4 <=space)) c–; This is the first loop and after this number of children gets decided in your code . What if : 1. space = 18 , children = 11 , men = 1 , women = 1 Answer should be take 8 children and 1 women and 1 man But your code gives output : 1 1 11 since you are not reducing c in this case .

1 Like

thank you I forget check women. is there another mistake in my code?

please can you say that why I get wrong answer:
I use s for capacity,m for men, w for women, c for child:
firstly I check how many children I can take. every 4 children I must take 1 adult so I check (c+3)/4<=m+w if it is true then I check there are any capacity for children and adult so I check. c+(c+3)/4<=s. if these two condition satisfy I don’t decreasing other way I decreasing until both condition satisfy. then I subtract child form capacity: s-=c. then I check how many women I can take. every 2 women I must take 1 man so first check (w+1)/2<=m if it is satisfy then I check there are any capacity for men and women : w+(w+1)/2<=s if these two condition satisfy I don’t decreasing other way I decreasing until both condition satisfy. then I subtract women from capacity s-=w. then I check if men’s more than capacity I take capacity m=s other way I take men. now what is my wrong that I get wrong answer?

please can you say that why I get wrong answer: I use s for capacity,m for men, w for women, c for child: firstly I check how many children I can take. every 4 children I must take 1 adult so I check (c+3)/4<=m+w
@shikimaru : What if w = 3 , m = 1 , c = 16 . You will allow c to be 16 right , which you cannot . As the answer given large capacity is c = 12 , w = 2 , m = 1 .
Sorry , I didn’t read beyond that .

but in you test how many we have capacity if we capacity more than 20 yes my program allow to take 16 children if less than 20 my program decreasing children. I mentioned “(c+3)/4<=m+w if it is true then I check there are any capacity for children and adult so I check. c+(c+3)/4<=s.”

yes , i wrote “given large capacity” , so i meant if capacity is say 25 , you will allow 16 children which is incorrect.