EOOPR - Editorial

This is what you are assuming brother.
You just have to focus on the mathematical side of the problem.
Where is it written that y=0 means lab is cleaned?
getting my point?

You code is failing on this input:

1
0 200

Expected output: 3
[Reason: 0(x)+101(a)+101(a)-2(b) , where ,a=101 (odd) , b=2 (even) ]

Your output: 2

Can you explain how in 2 steps you will solve this test case?

If
x = 1, y = 7
then, x+5, x+1
can be done in these two steps.

Also, if
x = 4, y = 12
(y-x) = 8, divisible by 4

Is it not correct to do in two steps by adding 7,and then adding 1??

1 Like

you can’t change a or b more than once.

How can we know for sure that for the case X > Y , there will only two possibilities unlike for case X>Y where there are three possibilities.

1 Like

for X >Y ,
we have to decrease X so obviously we will use b.

if X-Y==even , then definitely ,
1 step(minimum) is needed as we will take b=X-Y

if X-Y==Odd , Can we do it in 1 step ? Not possible,Right ?
If 1 can’t be taken as minimum no. of steps ,
we will surely prefer 2 as minimum no. of steps (Greedy)

Check whether 2 steps are possible for this case?
Yes it’s possible!
Add odd number(a) to X -------------------------(1st step)
Now, $X-Y=even , simply use b=X-Y------(2nd step)

As you know , 2 steps are minimum and we can’t do better than this.So why to think another possibility?

In X<Y, Minimum steps can be greater than 2,So we think of another possiblities to do minimize total number of steps.

You can check this explaination too - Click Here

2 Likes

thk

1 Like

a and b are constants hence we can’t change them.

ok. thanks a lot

1 Like

py_compile.PyCompileError: Sorry: TabError: inconsistent use of tabs and spaces in indentation (prog.py, line 6)
i am getting this error again and again with you code in Python.
help me out

I have corrected it.

hey brother
sorry to interrupt
if i have to go from 2 to 10
the difference is 8
i can do it in 2+ 7+1 = 10
making it only 2 steps
adding odd 7 and adding odd 1

1 Like

Hey Brother,
You cannot change a and b.
Either you can do 2+7+7 (if a = 7) or you can do 2+1+1 (if a = 1 )
You can refer this explanation - Click Here

Why is it wrong??

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

#include
using namespace std;

int main() {
long long t;
cin>>t;
while(t){
long long x,y,pd;
cin>>x>>y;
if(x==y){
std::cout << “1” << std::endl;
}
else if(y>x){
pd=y-x;
if(pd%2==0){
if((pd/2)%2==0){
cout<<“3”;
}
else if((pd/2)%2!=0){
cout<<“2”;
}
}
else
std::cout << “1” << std::endl;
}
else if(y<x){
pd=y-x;
if(pd%2==0){
cout<<“1”;
}
else
std::cout << “2” << std::endl;
}

    t--;
}
return 0;

}

What is wrong in this code ?

am javaScript developer. jest today opened CodeChef . How to Start it. and Where to find solutions in JS code. plz help me.

1 Like

Hi, anyone please tell me why did we use the difference between the X and Y. Because I am not to get this question like this my first question here.

1 Like

bro i am geting EOF error, even though i am using the editorial code. how to correct it

why i am getting EOF error with this solution, even i used the same code.

You can visit the problem and go to “all submissions” , then select you language and search.