 # MEENA_006 Editorial

Practice
Author: Yogesh Deolalkar
Tester: Ram Agrawal
Editorialist:Prathamesh Sogale

# DIFFICULTY:

CAKEWALK, SIMPLE.

Greedy, Math

# PROBLEM:

There is a grid of size 10^5×10^5, covered completely in railway tracks. Meena is riding in a train, currently in cell (a,b), and Vaibhav is tied up in a different cell (c,d), unable to move. The train has no breaks. It shall move exactly K steps, and then its fuel will run out and it shall stop. In one step, the train must move to one of its neighboring cells, sharing a side. Meena can’t move without the train, as the grid is covered in tracks. Can Meena reach Vaibhav’s cell after exactly K steps?

Note: Meena can go back to the same cell multiple times.

# SOLUTIONS:

Setter's Solution

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

int main() {
ll t;
std::cin >> t;
while(t–){
ll a,b,c,d,k;
cin >>a>>b>>c>>d>>k;
ll x=abs(c-a);
ll y=abs(d-b);
ll z=x+y;
if(k>=z){
if(k%2==z%2){
std::cout << “YES” << std::endl;
}
else{
std::cout << “NO” << std::endl;
}
}
else{
std::cout << “NO” << std::endl;
}
}

``````return 0;
``````

}

[details=“Tester’s Solution”]
#include
using namespace std;
int main(){
int t;
cin>>t;
while(t–){
int a,b,c,d,k;
cin>>a>>b>>c>>d>>k;
int min_1=0,min_2=0,max_1=0,max_2=0,sum=0;
if(a>=c){
min_1=c;
max_1=a;
}
else{
min_1=a;
max_1=c;
}
if(b>=d){
min_2=d;
max_2=b;
}
else{
min_2=b;
max_2=d;
}
sum=(max_1-min_1)+(max_2-min_2);
// cout<<sum<<endl;
if(sum==k){
cout<<“YES”<<endl;
}
else if(sum>k){
cout<<“NO”<<endl;
}
else{
if((k-sum)%2==0){
cout<<“YES”<<endl;
}
else{
cout<<“NO”<<endl;
}
}
}
}[/details]