 # SKYSCR - Editorial (LOCJUN16)

Author: Vaibhav Tulsyan
Editorialist: Arjit Srivastava

Cakewalk

Basic Maths

# Problem

Given two numbers A and B, find the minimum number of moves to make them equal - where every move takes one unit.

# Quick Explanation

The answer would always be the absolute difference between their values.

# Detailed Explanation

There are two ways by which we can ensure that the two given numbers end up being equal.
Reduce the number which is greater to the small number.
Increase the number which is smaller to the greater number.

Since, the cost of increasing a number and decreasing a number is the same, we can decipher that irrespective of the choice we make, we’ll have to use | A - B | units to make the two numbers equal.

# Pseudo-code

``````read a,b
print abs(a-b)
``````

20 points:
Using int data type in C/C++ would give 20 points.

100 points:
Notice that the constraint is 1018, so long long int data type will be needed to hold values as large as the constraints.

Languages like Python can use the their integer data type for this range still.

Editorialist’s solution

package contest;

import java.io.;
import java.util.
;

public class come {

``````public static void main(String[] args)throws IOException {

int s=t;
int i=0;
long N=0,M=0;
long k=0;
long r[]=new long;
while(t>0)
{
k=0;
String arr[]=lines.split(" ");
N=Long.valueOf(arr);
M=Long.valueOf(arr);
if(N>M)
{
k=N-M;
r[i]=k;
}
else if(M>N)
{
k=M-N;
r[i]=k;
}
else
{
k=0;
}
t--;
i++;
}
for(int j=0;j<s;j++)
{
System.out.println(r[j]);
}
}

}
// TODO Auto-generated method stub
``````

why it is showing wrong answer?

import java.util.;
import java.io.
;

class height {

``````public static void main(String[] args)throws IOException
{

int s=t;
int i=0;
long N=0,M=0;
long k=0;
long r[]=new long;
Scanner sc=new Scanner(System.in);
while(t>0)
{

k=0;

String arr[]=lines.split(" ");
N=Long.valueOf(arr);
M=Long.valueOf(arr);

int mid=(int)(N+M)/2;
while(N!=mid && M!=mid)
{
if(N>M)
{
N--;
k++;
M++;
k++;
r[i]=k;
}
else if(M>N)
{
M--;
k++;
N++;
k++;
r[i]=k;
}
}
while(N==mid && M!=mid)
{

if(mid>M)
{
M++;
k++;
r[i]=k;
}
else
{
M--;
k++;
r[i]=k;
}
}
while(M==mid && N!=mid)
{
if(mid>N)
{
N++;
k++;
r[i]=k;
}
else
{
N--;
k++;
r[i]=k;
}
}

t--;
i++;

}
for(int j=0;j<s;j++)
{
System.out.println(r[j]);
}
}
}
// TODO Auto-generated method stub
``````

why it is showing wrong answer??

ok its working now

@wittyceaser @admin2 Please provide editorials or some help for the problem ‘Maximum Disjoint Subarrays (MXSUBARR)’.

1 Like