using
System;
using
System.Collections.Generic;
public
class
GFG {
public
static
int
cmp(KeyValuePair<
int
,
int
> a,
KeyValuePair<
int
,
int
> b)
{
if
(a.Key > b.Key)
return
1;
return
-1;
}
public
static
int
getDistance(
int
[, ] arr,
int
n,
int
a,
int
b)
{
var
vp =
new
List<KeyValuePair<
int
,
int
> >();
for
(
int
i = 0; i < n; i++) {
vp.Add(
new
KeyValuePair<
int
,
int
>(arr[i, 0],
arr[i, 1]));
}
vp.Sort(cmp);
List<
int
> pos =
new
List<
int
>();
for
(
int
i = 0; i < 100; i++) {
pos.Add(0);
}
for
(
int
i = 0; i < vp.Count; i++) {
int
height = vp[i].Key;
int
k = vp[i].Value;
pos[k] = height;
}
int
first = -1, second = -1;
for
(
int
i = 0; i < pos.Count; i++) {
if
(pos[i] == a)
first = i;
if
(pos[i] == b)
second = i;
}
return
Math.Abs(first - second);
}
static
public
void
Main()
{
int
[, ] arr = { { 5, 0 }, { 3, 0 }, { 2, 0 },
{ 6, 4 }, { 1, 0 }, { 4, 3 } };
int
n = arr.GetLength(0);
int
a = 6, b = 5;
Console.WriteLine(getDistance(arr, n, a, b));
}
}