BRKBKS - Editorial

Maybe a bit harder (not the ussual implementation only problem), but definitely not evil (I mean there are no strange corner cases).

2 Likes

Has anyone solved this using proper use of stack and performing operations of reversal as asked in the question ?

2 Likes

@alei May I know if there are any corner cases for this problem, I got an error for the somewhat same code . Here is My code.

@line 23: I guess you meant else if

instead of

if(s>=w1+w2 or s>=w2+w3)

should be

else if(s>=w1+w2 or s>=w2+w3)

otherwise for some cases it will print two answers.

Hi @alei What if the input is 1 2 2 2 how many hits are required for this?

that is not a valid test case

in question it is mentioned that she is able to break all bricks so your test case is invalid

I also put the condition s1+s3<=s because also we can reverse by one,

why my solution gives partiallly correct,
if(w1+w2+w3<=s)
cout<<“1\n”;
else if(w1+w2<=s)
cout<<“2\n”;
else if(w1+w3<=s)
cout<<“2\n”;
else if(w2+w3<=s)
cout<<“2\n”;
else
cout<<"3

Consider the test case
2 1 2 1

I have just started on this, so just wanted to understand how to interpret these questions and test cases, as you said she is able to break all the bricks, how is she not able to break all bricks in 1 2 2 2, doesn’t she require to hit bricks 6 times to break them all.

1 Like

could you please tell me why the solution does not works
What i did is
for return value 1 sum >= sum of list
for return value 3 any 2 values must be >= s
else return 2
Below is the link to my code
https://www.codechef.com/viewsolution/30905863

can u tell why my code gives 50 percent score?
https://www.codechef.com/viewsolution/31911243

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

int main() {
int t;
cin>>t;
while(t–)
{
int s;
vector w(3);
cin>>s;
for(int i=0;i<3;i++)
cin>>w[i];
int k=accumulate(w.begin(),w.end(),0);
int rem=k%s;
int quot=k/s;
(rem==0)?cout<<quot<<endl : cout<<quot+1<<endl;
}
return 0;
}

What is wrong with my code ? Can anyone please explain ? Its showing WA. @vijju123 please help

@vijju123 sir i am getting wrong answer on running this code please help
#include <stdio.h>

int main(void) {
// your code goes here
int t;
scanf("%d",&t);
while(t–){
int s,w1,w2,w3;
scanf("%d%d%d%d",&s,&w1,&w2,&w3);
if (s >= w1 + w2 || s >= w2 + w3)
printf(“2\n”);
else if (s >= w1 + w2 + w3)
printf(“1\n”);
else
printf(“3\n”);
}
return 0;
}

@nmaan11612 in the question it is mentioned she will break all bricks

Does your code work on samples and custom input? In your while loop you did “t-“ instead of “t- -“. That makes me feel you got WA and you immediately asked for help without debugging yourself.

2 Likes

Thank you so much sir
I will try to be more cautious and patient next time

My brute force approach without reversing the bricks works. Can anyone tell the logic behind how this works.

https://www.codechef.com/viewsolution/33548180

what if S=1 and w1=w2=w3=2 , then answer is 6 ?