Problem:
Equilateral Triangular Fence
Ms. Misumi owns an orchard along a straight road.
Recently, wild boars have been witnessed strolling around the orchard aiming at pears, and she plans to construct a fence around many of the pear trees.
The orchard contains
n
pear trees, whose locations are given by the two-dimensional Euclidean coordinates (
x
1
,
y
1
),..., (
x
n
,
y
n
). For simplicity, we neglect the thickness of pear trees.
Ms. Misumi's aesthetic tells that the fence has to form a equilateral triangle with one of its edges parallel to the road.
Its opposite apex, of course,  should be apart from the road.
The coordinate system for the positions of the pear trees is chosen so that the road is expressed as
y
= 0, and the pear trees are located at
y
≥ 1.
Due to budget constraints, Ms. Misumi decided to allow at most
k
trees to be left outside of the fence.
You are to find the shortest possible perimeter of the fence on this condition.
The following figure shows the first dataset of the Sample Input.
There are four pear trees at (−1,2), (0,1), (1,2), and (2,1). 
By excluding (−1,2) from the fence, we obtain the equilateral triangle with perimeter 6.
Input
The input consists of multiple datasets, each in the following format.
n
k
x
1
y
1
...
x
n
y
n
Each of the datasets consists of
n
+2 lines.
n
in the first line is the integer representing the number of pear trees; it satisfies 3 ≤
n
≤ 10 000.
k
in the second line is the integer representing the number of pear trees that may be left outside of the fence; it satisfies 1 ≤
k
≤ min(
n
−2, 5 000).
The following
n
lines have two integers each representing the
x-
and
y-
coordinates, in this order, of the locations of pear trees; it satisfies −10 000 ≤
x
i
≤ 10 000, 1 ≤
y
i
≤ 10 000.
No two pear trees are at the same location, i.e., (
x
i
,
y
i
)=(
x
j
,
y
j
) only if
i
=
j
.
The end of the input is indicated by a line containing a zero.
The number of datasets is at most 100.
Output
For each dataset, output a single number that represents the shortest possible perimeter of the fence.
The output must not contain an error greater than 10
−6
.
Sample Input
4
1
0 1
1 2
-1 2
2 1
4
1
1 1
2 2
1 3
1 4
4
1
1 1
2 2
3 1
4 1
4
1
1 2
2 1
3 2
4 2
5
2
0 1
0 2
0 3
0 4
0 5
6
3
0 2
2 2
1 1
0 3
2 3
1 4
0
Output for the Sample Input
6.000000000000
6.928203230276
6.000000000000
7.732050807569
6.928203230276
6.000000000000

Submitted solutions:

code_snippet: #include <cstdio>
#include <cmath>
#include <algorithm>
const int N = 1e6 + 7;
double sq3 = sqrt(3.0);
struct Node {
 int x, y;
 double dx, dy;
} p[N], left[N], right[N], l[N], r[N];
int n, k;
bool cmp1(const Node &a, const Node &b) {
 return a.y<b.y || (a.y==b.y && a.x<b.x);
}
bool cmp2(const Node &a, const Node &b) {
 return a.dx>b.dx || (a.dx==b.dx && a.x<b.x);
}
bool cmp3(const Node &a, const Node &b) {
 return a.dy<b.dy || (a.dy==b.dy && a.x<b.x);
}
double check(int h, int k) {
 int cl = 0, cr = 0;
 double mn = 120000;
 for (int i = 1; i <= n; ++i) {
 if (left[i].y >= h) l[++cl] = left[i];
 if (right[i].y >= h) r[++cr] = right[i];
 }
 if (cl <= k) return mn;
 int rm = cl - k;//需要包含的点数
 //m 更新当前区域内包含的点数，j 为最右?点的下标
 //整个三?形从左向右移动
 for (int i = 1, m = rm, j = rm; i <= k+1;) {
 //若左移后的新的最左?点，之前没有加?，则 m+1
 if (l[i].dy > r[j].dy) ++m;
 while (m < rm) {
 if (j<cl && r[++j].dx>l[i].dx) continue;
 ++m;
 }
 if (j > cl) continue;

 if (r[j].dy < l[i].dy) mn = std::min(mn, (l[i].dy+l[i].dx-2*h)*sq3);
 else mn = std::min(mn, (r[j].dy+l[i].dx-2*h) * sq3);
 for (++i, --m; i<=k+1 && l[i].dx==l[i-1].dx; ++i, --m);
 }
 return mn;
}
int main() {
 while (~scanf("%d", &n) && n) {

 scanf("%d", &k); ++k;
 double mn = 120000;
 for (int i = 1; i <= n; ++i) {
 scanf("%d%d", &p[i].x, &p[i].y);
 p[i].dx = p[i].y - sq3 * p[i].x;
 p[i].dy = p[i].y + sq3 * p[i].x;
 left[i] = right[i] = p[i];
 }
 std::sort(p+1, p+n+1, cmp1);
 std::sort(left+1, left+n+1, cmp2);
 std::sort(right+1, right+n+1, cmp3);
 for (int i = 1; i <= k;) {
 double cir = check(p[i].y, k-i);
 if (cir < 120000) mn = std::min(mn, cir);
 for (++i; i<=k && p[i-1].y==p[i].y; ++i);
 }
 printf("%.12f\n", mn);
 }
 return 0;
}
accuracy: 1
time_ms: 1270
memory_kb: 13460
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
template <class T, class U>
inline bool chmax(T &a, U b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T, class U>
inline bool chmin(T &a, U b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline void compress(vector<T> &a) {
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
}
template <class T>
T rand(T l, T r) {
    static mt19937 mt(random_device{}());
    // [l, r)
    if constexpr (is_integral_v<T>) {
        return uniform_int_distribution<T>(l, r - 1)(mt);
    } else if constexpr (is_floating_point_v<T>) {
        return uniform_real_distribution<T>(l, r)(mt);
    }
}
constexpr int INF = 1001001001;
constexpr ll llINF = 3000000000000000010;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using pbds_set = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
using pbds_mset = tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>;
using pbds_umap = gp_hash_table<int, int>;
using pbds_trie = trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update>;
struct linear_sieve {
    vector<int> least_factor, prime_list;
    linear_sieve(int n) : least_factor(n + 1, 0) {
        for (int i = 2; i <= n; i++) {
            if (least_factor[i] == 0) {
                least_factor[i] = i;
                prime_list.push_back(i);
            }
            for (int p : prime_list) {
                if (ll(i) * p > n || p > least_factor[i]) break;
                least_factor[i * p] = p;
            }
        }
    }
};
template <int modulo>
struct modint {
    int x;
    modint() : x(0) {}
    modint(int64_t y) : x(y >= 0 ? y % modulo : (modulo - (-y) % modulo) % modulo) {}
    modint &operator+=(const modint &p) {
        if ((x += p.x) >= modulo) x -= modulo;
        return *this;
    }
    modint &operator-=(const modint &p) {
        if ((x += modulo - p.x) >= modulo) x -= modulo;
        return *this;
    }
    modint &operator*=(const modint &p) {
        x = (int)(1LL * x * p.x % modulo);
        return *this;
    }
    modint &operator/=(const modint &p) {
        *this *= p.inv();
        return *this;
    }
    modint operator-() const { return modint(-x); }
    modint operator+(const modint &p) const { return modint(*this) += p; }
    modint operator-(const modint &p) const { return modint(*this) -= p; }
    modint operator*(const modint &p) const { return modint(*this) *= p; }
    modint operator/(const modint &p) const { return modint(*this) /= p; }
    bool operator==(const modint &p) const { return x == p.x; }
    bool operator!=(const modint &p) const { return x != p.x; }
    modint inv() const {
        int a = x, b = modulo, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return modint(u);
    }
    modint pow(int64_t n) const {
        modint ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const modint &p) { return os << p.x; }
    friend istream &operator>>(istream &is, modint &a) {
        int64_t t;
        is >> t;
        a = modint<modulo>(t);
        return (is);
    }
    int val() const { return x; }
    static constexpr int mod() { return modulo; }
    static constexpr int half() { return (modulo + 1) >> 1; }
};
ll extgcd(ll a, ll b, ll &x, ll &y) {
    // ax+by=gcd(|a|,|b|)
    if (a < 0 || b < 0) {
        ll d = extgcd(abs(a), abs(b), x, y);
        if (a < 0) x = -x;
        if (b < 0) y = -y;
        return d;
    }
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
template <typename T>
struct Binomial {
    vector<T> inv, fact, factinv;
    Binomial(int n) {
        inv.resize(n + 1);
        fact.resize(n + 1);
        factinv.resize(n + 1);
        inv[0] = fact[0] = factinv[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i;
        factinv[n] = fact[n].inv();
        inv[n] = fact[n - 1] * factinv[n];
        for (int i = n - 1; i >= 1; i--) {
            factinv[i] = factinv[i + 1] * (i + 1);
            inv[i] = fact[i - 1] * factinv[i];
        }
    }
    T C(int n, int r) {
        if (n < 0 || n < r || r < 0) return 0;
        return fact[n] * factinv[n - r] * factinv[r];
    }
    T P(int n, int r) {
        if (n < 0 || n < r || r < 0) return 0;
        return fact[n] * factinv[n - r];
    }
    T H(int n, int r) {
        if (n == 0 && r == 0) return 1;
        if (n < 0 || r < 0) return 0;
        return r == 0 ? 1 : C(n + r - 1, r);
    }
};
template <class T>
struct Matrix {
    vector<vector<T>> m;
    Matrix() = default;
    Matrix(int x) : m(vector(x, vector<T>(x, 0))) {}
    Matrix(const vector<vector<T>> &a) : m(a) {}
    vector<T> &operator[](int i) { return m[i]; }
    const vector<T> &operator[](int i) const { return m[i]; }
    static Matrix identity(int x) {
        Matrix res(x);
        for (int i = 0; i < x; i++) res[i][i] = 1;
        return res;
    }
    static Matrix zero(int x) { return Matrix(x); }

    Matrix operator+() const { return (*this); }
    Matrix operator-() const { return Matrix(this->m.size()) - (*this); }
    Matrix operator+(const Matrix &a) const {
        Matrix x = (*this);
        return x += a;
    }
    Matrix operator-(const Matrix &a) const {
        Matrix x = (*this);
        return x -= a;
    }
    Matrix operator*(const Matrix &a) const {
        Matrix x = (*this);
        return x *= a;
    }
    Matrix operator*(const T &a) const {
        Matrix x = (*this);
        return x *= a;
    }
    Matrix &operator+=(const Matrix &a) {
        int n = m.size();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                m[i][j] += a[i][j];
            }
        }
        return *this;
    }
    Matrix &operator-=(const Matrix &a) {
        int n = m.size();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                m[i][j] -= a[i][j];
            }
        }
        return *this;
    }
    Matrix &operator*=(const Matrix &a) {
        int n = m.size();
        Matrix res(n);
        for (int i = 0; i < n; i++) {
            for (int k = 0; k < n; k++) {
                for (int j = 0; j < n; j++) {
                    res[i][j] += m[i][k] * a[k][j];
                }
            }
        }
        m = res.m;
        return *this;
    }
    Matrix &operator*=(const T &a) {
        int n = m.size();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                m[i][j] *= a;
            }
        }
        return *this;
    }
    Matrix pow(ll b) const {
        Matrix x = *this, res = identity(x.m.size());
        while (b) {
            if (b & 1) {
                res *= x;
            }
            x *= x;
            b >>= 1;
        }
        return res;
    }
    T determinant() {
        int n = m.size();
        Matrix A(*this);
        T ret = 1;
        for (int i = 0; i < n; i++) {
            int pivot = -1;
            for (int j = i; j < n; j++) {
                if (A[j][i] != 0) pivot = j;
            }
            if (pivot == -1) return T(0);
            if (i != pivot) {
                ret *= -1;
                swap(A[i], A[pivot]);
            }
            ret *= A[i][i];
            T tmp = T(1) / A[i][i];
            for (int j = 0; j < n; j++) {
                A[i][j] *= tmp;
            }
            for (int j = i + 1; j < n; j++) {
                T a = A[j][i];
                for (int k = 0; k < n; k++) {
                    A[j][k] -= A[i][k] * a;
                }
            }
        }
        return ret;
    }
    Matrix inverse() {
        assert(determinant() != 0);
        int n = m.size();
        Matrix ret = identity(n);
        Matrix A(*this);
        for (int i = 0; i < n; i++) {
            int pivot = -1;
            for (int j = i; j < n; j++) {
                if (A[j][i] != 0) pivot = j;
            }
            if (i != pivot) {
                swap(ret[i], ret[pivot]);
                swap(A[i], A[pivot]);
            }
            T tmp = T(1) / A[i][i];
            for (int j = 0; j < n; j++) {
                A[i][j] *= tmp;
                ret[i][j] *= tmp;
            }
            for (int j = 0; j < n; j++) {
                if (j == i) continue;
                T a = A[j][i];
                for (int k = 0; k < n; k++) {
                    A[j][k] -= A[i][k] * a;
                    ret[j][k] -= ret[i][k] * a;
                }
            }
        }
        return ret;
    }
    vector<T> characteristic_polynomial() {
        int n = m.size();
        if (n == 0) return {1};
        Matrix A(*this);
        for (int i = 1; i < n; i++) {
            int pivot = -1;
            for (int j = i; j < n; j++) {
                if (A[j][i - 1] != 0) pivot = j;
            }
            if (pivot == -1) continue;
            if (i != pivot) {
                swap(A[i], A[pivot]);
                for (int j = 0; j < n; j++) swap(A[j][i], A[j][pivot]);
            }
            T tmp = T(1) / A[i][i - 1];
            vector<T> c(n);
            for (int j = i + 1; j < n; j++) c[j] = tmp * A[j][i - 1];
            for (int j = i + 1; j < n; j++) {
                for (int k = i - 1; k < n; k++) {
                    A[j][k] -= A[i][k] * c[j];
                }
            }
            for (int j = 0; j < n; j++) {
                for (int k = i + 1; k < n; k++) {
                    A[j][i] += A[j][k] * c[k];
                }
            }
        }
        vector dp(n + 1, vector<T>(n + 1));
        dp[0][0] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= i; j++) {
                dp[i + 1][j] -= dp[i][j] * A[i][i];
                dp[i + 1][j + 1] += dp[i][j];
            }
            T p = 1;
            for (int k = i + 1; k < n; k++) {
                p *= A[k][k - 1];
                for (int j = 0; j <= i; j++) dp[k + 1][j] -= dp[i][j] * p * A[i][k];
            }
        }
        return dp[n];
    }
    friend ostream &operator<<(ostream &os, const Matrix &a) {
        int n = a.m.size();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                os << a[i][j];
                if (j != n - 1) os << " ";
            }
            os << "\n";
        }
        return os;
    }
    friend istream &operator>>(istream &is, Matrix &a) {
        int n = a.m.size();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                is >> a[i][j];
            }
        }
        return is;
    }
};

template <class T, T (*op)(T, T), T (*e)()>
struct disjointsparsetable {
    vector<vector<T>> table;
    vector<int> logtable;
    disjointsparsetable() = default;
    disjointsparsetable(vector<T> v) {
        int len = 0;
        while ((1 << len) <= v.size()) len++;
        table.assign(len, vector<T>(1 << len, e()));
        for (int i = 0; i < (int)v.size(); i++) table[0][i] = v[i];
        for (int i = 1; i < len; i++) {
            int shift = 1 << i;
            for (int j = 0; j < (int)v.size(); j += shift << 1) {
                int t = min(j + shift, (int)v.size());
                table[i][t - 1] = v[t - 1];
                for (int k = t - 2; k >= j; k--) table[i][k] = op(v[k], table[i][k + 1]);
                if (v.size() <= t) break;
                table[i][t] = v[t];
                int r = min(t + shift, (int)v.size());
                for (int k = t + 1; k < r; k++) table[i][k] = op(table[i][k - 1], v[k]);
            }
        }
        logtable.resize(1 << len);
        for (int i = 2; i < logtable.size(); i++) {
            logtable[i] = logtable[(i >> 1)] + 1;
        }
    }
    T query(int l, int r) {
        if (l == r) return e();
        if (l >= --r) return table[0][l];
        int len = logtable[l ^ r];
        return op(table[len][l], table[len][r]);
    };
};
pair<int, int> lcatree_op(pair<int, int> a, pair<int, int> b) { return min(a, b); }
pair<int, int> lcatree_e() { return {1000000000, -1}; }
struct lca_tree {
    int n, size;
    vector<int> in, ord, depth;
    disjointsparsetable<pair<int, int>, lcatree_op, lcatree_e> st;
    lca_tree(vector<vector<int>> g, int root = 0) : n((int)g.size()), size(log2(n) + 2), in(n), depth(n, n) {
        depth[root] = 0;
        function<void(int, int)> dfs = [&](int v, int p) {
            in[v] = (int)ord.size();
            ord.push_back(v);
            for (int u : g[v]) {
                if (u == p) continue;
                if (depth[u] > depth[v] + 1) {
                    depth[u] = depth[v] + 1;
                    dfs(u, v);
                    ord.push_back(v);
                }
            }
        };
        dfs(root, -1);
        vector<pair<int, int>> vec((int)ord.size());
        for (int i = 0; i < (int)ord.size(); i++) {
            vec[i] = make_pair(depth[ord[i]], ord[i]);
        }
        st = vec;
    }
    int lca(int u, int v) {
        if (in[u] > in[v]) swap(u, v);
        if (u == v) return u;
        return st.query(in[u], in[v]).second;
    }
    int dist(int u, int v) {
        int l = lca(u, v);
        return depth[u] + depth[v] - 2 * depth[l];
    }
};
struct auxiliary_tree : lca_tree {
    vector<vector<int>> G;
    auxiliary_tree(vector<vector<int>> &g) : lca_tree(g), G(n) {}
    pair<int, vector<int>> query(vector<int> vs, bool decending = false) {
        assert(!vs.empty());
        sort(vs.begin(), vs.end(), [&](int a, int b) { return in[a] < in[b]; });
        int m = vs.size();
        stack<int> st;
        st.push(vs[0]);
        for (int i = 0; i < m - 1; i++) {
            int w = lca(vs[i], vs[i + 1]);
            if (w != vs[i]) {
                int l = st.top();
                st.pop();
                while (!st.empty() && depth[w] < depth[st.top()]) {
                    if (!decending) G[l].push_back(st.top());
                    G[st.top()].push_back(l);
                    l = st.top();
                    st.pop();
                }
                if (st.empty() || st.top() != w) {
                    st.push(w);
                    vs.push_back(w);
                }
                if (!decending) G[l].push_back(w);
                G[w].push_back(l);
            }
            st.push(vs[i + 1]);
        }
        while (st.size() > 1) {
            int x = st.top();
            st.pop();
            if (!decending) G[x].push_back(st.top());
            G[st.top()].push_back(x);
        }
        // {root,vertex_list}
        return make_pair(st.top(), vs);
    }
    void clear(vector<int> vs) {
        for (int v : vs) G[v].clear();
    }
};
template <class T>
vector<T> dijkstra(vector<vector<pair<int, T>>> &g, vector<int> start) {
    using P = pair<T, int>;
    vector<T> dp(g.size(), numeric_limits<T>::max());
    priority_queue<P, vector<P>, greater<P>> que;
    for (int s : start) {
        dp[s] = 0;
        que.push({0, s});
    }
    while (que.size()) {
        auto [d, v] = que.top();
        que.pop();
        if (dp[v] != d) continue;
        for (auto [u, c] : g[v]) {
            if (chmin(dp[u], d + c)) que.push({dp[u], u});
        }
    }
    return dp;
}

vector<int> BFS01(vector<vector<pair<int, int>>> &g, vector<int> start) {
    vector<int> dp(g.size(), numeric_limits<int>::max());
    deque<int> que;
    for (int s : start) {
        dp[s] = 0;
        que.push_front(s);
    }
    while (que.size()) {
        auto v = que.front();
        que.pop_front();
        for (auto [u, c] : g[v]) {
            if (chmin(dp[u], dp[v] + c)) {
                if (c == 0)
                    que.push_front(u);
                else
                    que.push_back(u);
            }
        }
    }
    return dp;
}
struct Mo {
    int n;
    vector<pair<int, int>> lr;

    explicit Mo(int n) : n(n) {}

    void add(int l, int r) { /* [x, y) */ lr.emplace_back(l, r); }

    template <typename AL, typename AR, typename EL, typename ER, typename O>
    void build(const AL &add_left, const AR &add_right, const EL &erase_left, const ER &erase_right, const O &out) {
        int q = (int)lr.size();
        int bs = max<int>(1, 1.0 * n / max<double>(1.0, sqrt(q * 2.0 / 3.0)));
        vector<int> ord(q);
        iota(begin(ord), end(ord), 0);
        sort(begin(ord), end(ord), [&](int a, int b) {
            int ablock = lr[a].first / bs, bblock = lr[b].first / bs;
            if (ablock != bblock) return ablock < bblock;
            return (ablock & 1) ? lr[a].second > lr[b].second : lr[a].second < lr[b].second;
        });
        int l = 0, r = 0;
        for (auto idx : ord) {
            while (l > lr[idx].first) add_left(--l);
            while (r < lr[idx].second) add_right(r++);
            while (l < lr[idx].first) erase_left(l++);
            while (r > lr[idx].second) erase_right(--r);
            out(idx);
        }
    }

    template <typename A, typename E, typename O>
    void build(const A &add, const E &erase, const O &out) {
        build(add, add, erase, erase, out);
    }
};
template <class S, S (*op)(S, S), S (*e)()>
struct dual_segtree {
    int sz = 1, log = 0;
    vector<S> lz;
    dual_segtree() = default;
    dual_segtree(int n) : dual_segtree(vector<S>(n, e())) {}
    dual_segtree(vector<S> a) {
        int n = a.size();
        while (sz < n) {
            sz <<= 1;
            log++;
        }
        lz.assign(sz << 1, e());
        for (int i = 0; i < n; i++) lz[i + sz] = a[i];
    }
    void push(int k) {
        int b = __builtin_ctz(k);
        for (int d = log; d > b; d--) {
            lz[k >> d << 1] = op(lz[k >> d << 1], lz[k >> d]);
            lz[k >> d << 1 | 1] = op(lz[k >> d << 1 | 1], lz[k >> d]);
            lz[k >> d] = e();
        }
    }
    void apply(int l, int r, S x) {
        l += sz, r += sz;
        push(l);
        push(r);
        while (l < r) {
            if (l & 1) {
                lz[l] = op(lz[l], x);
                l++;
            }
            if (r & 1) {
                r--;
                lz[r] = op(lz[r], x);
            }
            l >>= 1, r >>= 1;
        }
    }
    S get(int k) {
        k += sz;
        S res = e();
        while (k) {
            res = op(res, lz[k]);
            k >>= 1;
        }
        return res;
    }
};

struct LowLink {
    vector<vector<int>> g;
    vector<int> ord, low, out;
    vector<bool> used;
    vector<pair<int, int>> bridge;
    vector<pair<int, int>> articulation;
    int unions;
    LowLink(vector<vector<int>> g) : g(g) {
        int n = (int)g.size();
        ord.resize(n);
        low.resize(n);
        out.resize(n);
        used.resize(n);
        unions = 0;
        int t = 0;
        for (int i = 0; i < n; i++) {
            if (!used[i]) {
                dfs(i, t, -1);
                unions++;
            }
        }
    }
    void dfs(int v, int &t, int par) {
        used[v] = true;
        ord[v] = t++, low[v] = ord[v];
        int cnt = 0;
        bool par_back = false;
        for (int to : g[v]) {
            if (!used[to]) {
                dfs(to, t, v);
                low[v] = min(low[v], low[to]);
                if (ord[v] < low[to]) bridge.push_back(minmax(v, to));
                if (ord[v] <= low[to]) cnt++;
            } else if (to != par || par_back) {
                low[v] = min(low[v], ord[to]);
            } else
                par_back = true;
        }
        if (par != -1) cnt++;
        if (cnt >= 2) articulation.push_back({v, cnt});
        out[v] = t;
    }
};
void solve() {
    int n;
    cin >> n;
    if (n == 0) exit(0);
    int k;
    cin >> k;
    vector<tuple<int, int, int>> ps(n);
    rep(i, n) {
        int x, y;
        cin >> x >> y;
        ps[i] = {y, x, i};
    }
    sort(all(ps), [&](auto p, auto q) { return get<0>(p) + sqrt(3) * get<1>(p) < get<0>(q) + sqrt(3) * get<1>(q); });
    vector<pair<int, int>> point(n);
    rep(i, n) {
        get<2>(ps[i]) = i;
        point[i] = make_pair(get<0>(ps[i]), get<1>(ps[i]));
    }
    sort(all(ps));
    vector<int> Ys;
    rep(lb, k + 1) Ys.push_back(get<0>(ps[lb]));
    sort(all(ps), [&](auto p, auto q) { return -get<0>(p) + sqrt(3) * get<1>(p) > -get<0>(q) + sqrt(3) * get<1>(q); });
    double ans = INF;
    for (auto Y : Ys) {
        vector<bool> exist(n);
        int mx = n - 1;  // n-k th
        int cnt = 0;
        for (auto [y, x, i] : ps) {
            if (y < Y) continue;
            if (mx >= i) {
                exist[i] = true;
                cnt++;
            }
            while (cnt >= n - k) {
                if(!exist[mx]){
                    mx--;
                }
                else if (cnt>n-k) {
                    exist[mx] = false;
                    cnt--;
                }else break;
            }
            if (cnt == n - k) {
                auto [y2, x2] = point[mx];
                double xl = x + (Y - y) / sqrt(3);
                double xr = x2 + (y2 - Y) / sqrt(3);
                chmin(ans, 3 * (xr - xl));
            }
        }
    }
    printf("%.12lf\n", ans);
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while (1) solve();
}
accuracy: 1
time_ms: 1570
memory_kb: 3768
final_rank: 1

code_snippet: // AOJ 1629 Equilateral Triangular Fence
// 2025.5.3

#include <bits/stdc++.h>
using namespace std;
const double SQ3 = sqrt(3.0);

const int MAXN = 1<<18;
double X[MAXN], Y[MAXN], Lval[MAXN], Rval[MAXN];
int idxL[MAXN], idxR[MAXN];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    while(true) {
        int N, K;
        cin >> N;
        if (N == 0) break;
        cin >> K;
        int req = N - K;

        for(int i = 0; i < N; i++){
            cin >> X[i] >> Y[i];
            double x = X[i], y = Y[i];
            Lval[i] = SQ3 * x - y;
            Rval[i] = SQ3 * x + y;
            idxL[i] = idxR[i] = i;
        }

        sort(idxL, idxL + N, [&](int a, int b){
            return Lval[a] < Lval[b];
        });
        sort(idxR, idxR + N, [&](int a, int b){
            return Rval[a] < Rval[b];
        });

        vector<double> ys(Y, Y + N);
        sort(ys.begin(), ys.end());
        ys.erase(unique(ys.begin(), ys.end()), ys.end());

        double ans = 1e18;
        for(double y0 : ys){
            int cur = 0, cnt = 0;
            for(int j = 0; j < N; j++){
                int iL = idxL[j];
                double border = Lval[iL];

                while(cur < N && cnt < req){
                    int iR = idxR[cur++];
                    if(Y[iR] >= y0 && Lval[iR] >= border) cnt++;
                }
                if(cnt < req) break;

                double cl = (border + y0) / SQ3;
                double cr = (Rval[idxR[cur-1]] - y0) / SQ3;
                ans = min(ans, 3.0 * (cr - cl));
                if(Y[iL] >= y0 && Rval[iL] <= Rval[idxR[cur-1]]) cnt--;
            }
        }
        printf("%.7lf\n", ans);
    }
    return 0;
}
accuracy: 1
time_ms: 1520
memory_kb: 11864
final_rank: 17

code_snippet: // AOJ 1629 Equilateral Triangular Fence
// 2025.5.3

#include <bits/stdc++.h>
using namespace std;
const double SQ3 = sqrt(3.0);

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    while(true){
        int N;
        cin >> N;
        if(N == 0) break;
        int K;
        cin >> K;
        int req = N - K;

        vector<double> X(N), Y(N);
        for(int i = 0; i < N; i++) cin >> X[i] >> Y[i];

        vector<pair<double,int>> L, R;
        L.reserve(N);
        R.reserve(N);
        for(int i = 0; i < N; i++){
            L.emplace_back(SQ3 * X[i] - Y[i], i);
            R.emplace_back(SQ3 * X[i] + Y[i], i);
        }
        sort(L.begin(), L.end());
        sort(R.begin(), R.end());

        vector<double> ys = Y;
        sort(ys.begin(), ys.end());
        ys.erase(unique(ys.begin(), ys.end()), ys.end());

        double ans = 1e18;
        for(double y0 : ys){
            int cur = 0, cnt = 0;
            for(int j = 0; j < N; j++){
                double border = L[j].first;

                while(cur < N && cnt < req){
                    int idx = R[cur].second;
                    if(Y[idx] >= y0 && (SQ3*X[idx] - Y[idx]) >= border) cnt++;
                    cur++;
                }
                if(cnt < req) break;

                double cl = (border + y0) / SQ3;
                double cr = (R[cur-1].first - y0) / SQ3;
                ans = min(ans, 3.0 * (cr - cl));

                int idx2 = L[j].second;
                if(Y[idx2] >= y0 && (SQ3*X[idx2] + Y[idx2]) <= R[cur-1].first) cnt--;
            }
        }
        printf("%.7lf\n", ans);
    }
    return 0;
}
accuracy: 1
time_ms: 1540
memory_kb: 3920
final_rank: 2

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

int main() {
    double sq3 = sqrt(3.0);
while(1) {
    int N, K;
    cin >> N >> K;
    if (N == 0) return 0;
    vector<pair<double,double>> P(N);
    rep(i,0,N) cin >> P[i].first >> P[i].second;
    sort(ALL(P),[](pair<double,double> P1, pair<double,double> P2){return P1.second < P2.second;});
    auto CalcL = [&](int i) -> double {
        return P[i].first - P[i].second/sq3;
    };
    auto CalcR = [&](int i) -> double {
        return P[i].first + P[i].second/sq3;
    };
    vector<pair<double,int>> XL, XR;
    rep(i,0,N) XL.push_back({CalcL(i),i}), XR.push_back({CalcR(i),i});
    sort(ALL(XL)), sort(ALL(XR));
    double ANS = INF;
    rep(i,0,K+1) {
        int L = 0, R = 0, COUNT = 0;
        while(L < N) {
            while(R < N && COUNT < N-K) {
                R++;
                if (XR[R-1].second >= i && CalcL(XR[R-1].second) >= XL[L].first) COUNT++;
            }
            if (R == N && COUNT < N-K) break;
            chmin(ANS, (XR[R-1].first-P[i].second/sq3)-(XL[L].first+P[i].second/sq3));
            if (XL[L].second >= i && CalcR(XL[L].second) <= XR[R-1].first) COUNT--;
            L++;
        }
    }
    printf("%.12f\n", ANS*3.0);
}
}
accuracy: 1
time_ms: 1700
memory_kb: 4172
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef pair<ll,ll> pi;
typedef pair<ll,pi> ppi;
#define FOR(i,l,r) for(ll i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,l,r) for(ll i=r-1;i>=l;i--)
#define RREP(i,n) RFOR(i,0,n)
#define sz(A) (ll)(A.size())
#define ALL(A) A.begin(),A.end()
#define LB(A,x) (ll)(lower_bound(ALL(A),x)-A.begin())
#define UB(A,x) (ll)(upper_bound(ALL(A),x)-A.begin())
#define COU(A,x) (UB(A,x)-LB(A,x))
#define F first
#define S second
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.F<<" "<<p.S;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.F>>p.S;return is;}
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){REP(i,sz(v))os<<v[i]<<(i+1!=sz(v)?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<class T>bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,T b){if(b<a){a=b;return 1;}return 0;}
const ll mod=998244353;
template<const long long int mod=998244353>
struct modint{
  using mint=modint<mod>;
  long long int x;
  modint(long long int _x=0):x(_x%mod){if(x<0)x+=mod;}
  long long int val(){return x;}
  mint&operator=(const mint&a){x=a.x;return *this;}
  mint&operator+=(const mint&a){x+=a.x;if(x>=mod)x-=mod;return *this;}
  mint&operator-=(const mint&a){x-=a.x;if(x<0)x+=mod;return *this;}
  mint&operator*=(const mint&a){x*=a.x;x%=mod;return *this;}
  friend mint operator+(const mint&a,const mint&b){return mint(a)+=b;}
  friend mint operator-(const mint&a,const mint&b){return mint(a)-=b;}
  friend mint operator*(const mint&a,const mint&b){return mint(a)*=b;}
  mint operator-()const{return mint(0)-*this;}
  mint pow(long long int n){
    if(!n)return 1;
    mint a=1;
    mint _x=x;
    while(n){
      if(n&1)a*=_x;
      _x=_x*_x;n>>=1;
    }
    return a;
  }
  mint inv(){return pow(mod-2);}
  mint&operator/=(mint&a){return *this*=a.inv();}
  friend mint operator/(const mint&a,mint b){return mint(a)/=b;}
};
using mint=modint<998244353>;
int main(){
    while(1){
      ll N,K;cin>>N>>K;
      if(!N)return 0;
      vector<pi>A(N);cin>>A;
      sort(ALL(A),[](pi a,pi b){return a.S>b.S;});
      auto f=[](pi a,pi b){
        ll x=a.F-b.F,y=b.S-a.S;
        if(x*y<=0)return x>y;
        if(x<0)return 3*x*x<y*y;
        return 3*x*x>y*y;
      };
      auto g=[](pi a,pi b){
        ll x=a.F-b.F,y=a.S-b.S;
        if(x*y<=0)return x<y;
        if(x<0)return 3*x*x>y*y;
        return 3*x*x<y*y;
      };
      auto B=A;
      sort(ALL(B),f);
      vi tr(N);
      REP(i,N)REP(j,N)if(A[i]==B[j])tr[j]=i;
      ld ans=1e18;
      REP(i,N){
        ll l=0,r=0,cnt=0;
        vb used(N);
        REP(j,N){
            ld fy=(ld)0.5*(A[i].S+B[j].S+(ld)sqrt(3)*(B[j].F-A[i].F));
            ll y=fy+1e-9;
            while(l<N&&A[l].S>y){
                if(used[l])cnt--,used[l]=0;
                l++;
            }
            chmax(r,l);
            while(r<N&&(cnt<N-K)){
                if((!f(A[r],B[j]))&&(!g(A[r],A[i])))cnt++,used[r]=1;
                r++;
            }
            if(cnt<N-K)break;
            if((!f(A[i],B[j]))&&(!g(B[j],A[i])))chmin(ans,(fy-min({A[r-1].S,A[i].S,B[j].S}))*2*sqrt(3));
            if(used[tr[j]]){
              used[tr[j]]=0;cnt--;
            }
        }
      }
      printf("%.20Lf\n",ans);
    }
    return 0;
}
accuracy: 1
time_ms: 5970
memory_kb: 3660
final_rank: 11

code_snippet: #include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
const double sqrt3=1.7320508075688772;
const double inv_sqrt3=double(1)/sqrt3;
int N,K,X[10101],Y[10101];
int cand_y[10101];
int L[10101],R[10101];
pair<double,int>Ls[10101],Rs[10101];
tuple<double,int,bool>cand_x[20202];
bool checked[10101];
bool solve(){
    cin>>N;
    if(N==0)return false;
    cin>>K;
    for(int i=0;i<N;i++)
    {
        cin>>X[i]>>Y[i];
        Ls[i].first=X[i]-Y[i]*inv_sqrt3;
        Rs[i].first=X[i]+Y[i]*inv_sqrt3;
        Ls[i].second=Rs[i].second=i;
        cand_y[i]=Y[i];
    }
    sort(Ls,Ls+N);
    sort(Rs,Rs+N);
    sort(cand_y,cand_y+N);
    for(int i=0;i<=cand_y[N-1];i++)checked[i]=false;
    double ans=1e150;
    for(int k=0;k<N;k++)
    {
        int t=cand_y[k];
        if(checked[t])continue;
        checked[t]=true;
        int i=0,j=0;
        int M=0;
        while(i<N||j<N)
        {
            // insert R
            if(i==N)
            {
                auto[x,y]=Rs[j];
                j++;
                if(Y[y]<t)continue;
                cand_x[M++]=make_tuple(x-t*inv_sqrt3,y,false);
            }
            // insert L
            else if(j==N)
            {
                auto[x,y]=Ls[i];
                i++;
                if(Y[y]<t)continue;
                cand_x[M++]=make_tuple(x+t*inv_sqrt3,y,true);
            }
            else
            {
                auto[xl,yl]=Ls[i];
                auto[xr,yr]=Rs[j];
                // insert L
                if(xl+t*inv_sqrt3<xr-t*inv_sqrt3)
                {
                    i++;
                    if(Y[yl]<t)continue;
                    cand_x[M++]=make_tuple(xl+t*inv_sqrt3,yl,true);
                }
                // insert R
                else
                {
                    j++;
                    if(Y[yr]<t)continue;
                    cand_x[M++]=make_tuple(xr-t*inv_sqrt3,yr,false);
                }
            }
        }
        if(M<2*N-2*K)break;
        for(int i=0;i<M;i++)
        {
            auto[x,idx,is_left]=cand_x[i];
            if(is_left)L[idx]=i;
            else R[idx]=i;
        }
        int r=0,cnt=0;
        for(int l=0;l<M;l++)
        {
            while(r<M&&cnt<N-K)
            {
                auto[x,idx,is_left]=cand_x[r];
                if(!is_left&&l<=L[idx])cnt++;
                r++;
            }
            double d=get<0>(cand_x[r-1])-get<0>(cand_x[l]);
            if(cnt>=N-K)ans=min(ans,3*d);
            if(get<2>(cand_x[l])&&R[get<1>(cand_x[l])]<r)cnt--;
        }
    }
    cout<<fixed<<setprecision(16)<<ans<<'\n';
    return true;
}
int main(){while(solve()){}}
accuracy: 1
time_ms: 6730
memory_kb: 4304
final_rank: 14

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;
const double sqrt3=sqrtl(double(3.0));
const double inv_sqrt3=double(1)/sqrt3;
bool solve(){
    int N;
    cin>>N;
    if(N==0)return false;
    int K;
    cin>>K;
    vector<int>X(N),Y(N);
    for(int i=0;i<N;i++)cin>>X[i]>>Y[i];
    vector<pair<double,int>>Ls(N),Rs(N);
    vector<int>cand_y(N);
    for(int i=0;i<N;i++)
    {
        Ls[i].first=X[i]-Y[i]*inv_sqrt3;
        Rs[i].first=X[i]+Y[i]*inv_sqrt3;
        Ls[i].second=Rs[i].second=i;
        cand_y[i]=Y[i];
    }
    sort(Ls.begin(),Ls.end());
    sort(Rs.begin(),Rs.end());
    sort(cand_y.begin(),cand_y.end());
    cand_y.erase(unique(cand_y.begin(),cand_y.end()),cand_y.end());
    double ans=1e150;
    for(int t:cand_y)
    {
        vector<tuple<double,int,bool>>cand_x; // (x, i, is_L)
        cand_x.reserve(2*N);
        int i=0,j=0;
        while(i<N||j<N)
        {
            // insert R
            if(i==N)
            {
                auto[x,y]=Rs[j];
                j++;
                if(Y[y]<t)continue;
                cand_x.push_back(make_tuple(x-t*inv_sqrt3,y,false));
            }
            // insert L
            else if(j==N)
            {
                auto[x,y]=Ls[i];
                i++;
                if(Y[y]<t)continue;
                cand_x.push_back(make_tuple(x+t*inv_sqrt3,y,true));
            }
            else
            {
                auto[xl,yl]=Ls[i];
                auto[xr,yr]=Rs[j];
                // insert L
                if(xl+t*inv_sqrt3<xr-t*inv_sqrt3)
                {
                    i++;
                    if(Y[yl]<t)continue;
                    cand_x.push_back(make_tuple(xl+t*inv_sqrt3,yl,true));
                }
                // insert R
                else
                {
                    j++;
                    if(Y[yr]<t)continue;
                    cand_x.push_back(make_tuple(xr-t*inv_sqrt3,yr,false));
                }
            }
        }
        vector<int>L(N,-1),R(N,-1);
        for(int i=0;i<cand_x.size();i++)
        {
            auto[x,idx,is_left]=cand_x[i];
            if(is_left)L[idx]=i;
            else R[idx]=i;
        }
        // for(auto[x,f]:cand_x)cout<<fixed<<setprecision(3)<<x<<' ';cout<<endl;
        int r=0,cnt=0;
        for(int l=0;l<cand_x.size();l++)
        {
            while(r<cand_x.size()&&cnt<N-K)
            {
                auto[x,idx,is_left]=cand_x[r];
                if(!is_left&&l<=L[idx])cnt++;
                r++;
            }
            double d=get<0>(cand_x[r-1])-get<0>(cand_x[l]);
            if(cnt>=N-K)ans=min(ans,3*d);
            if(get<2>(cand_x[l])&&R[get<1>(cand_x[l])]<r)cnt--;
        }
    }
    cout<<fixed<<setprecision(16)<<ans<<'\n';
    return true;
}
int main(){while(solve()){}}
accuracy: 1
time_ms: 10790
memory_kb: 4180
final_rank: 19

code_snippet: #include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;

template <class T, T (*ide)(), T (*ope)(T, T)>
struct segment_tree
{
    int n;
    vector<T> node;

    segment_tree() {}
    segment_tree(const vector<T> &init)
    {
        n = 1;
        while (n < init.size())
            n *= 2;
        node.resize(2 * n, ide());
        for (int i = 0; i < init.size(); i++)
            node[i + n] = init[i];
        for (int i = n; i-- > 1;)
            node[i] = ope(node[i * 2], node[i * 2 + 1]);
    } ///

    void update(int i, T x)
    {
        i += n;
        node[i] = x;
        while (i > 1)
        {
            i >>= 1;
            node[i] = ope(node[i * 2], node[i * 2 + 1]);
        }
    }

    T sum(int l, int r) const
    {
        T lx = ide();
        T rx = ide();
        l += n;
        r += n;
        while (l < r)
        {
            if (l & 1)
            {
                lx = ope(lx, node[l++]);
            }
            if (r & 1)
            {
                rx = ope(node[--r], rx);
            }
            l >>= 1;
            r >>= 1;
        }
        return ope(lx, rx);
    }

    const T &at(int i) const
    {
        return node[i + n];
    } ///

    template <class F>
    int subtree_down_first(int i, T lx, F isok) const
    {
        while (i < n)
        {
            T next = ope(lx, node[i * 2]);
            if (isok(next))
                i = i * 2;
            else
            {
                lx = next;
                i = i * 2 + 1;
            }
        }
        return i - n + 1;
    }

    template <class F>
    int find_first(int l, F isok) const
    {
        if (isok(ide()))
        {
            return l;
        }
        if (l == 0)
        {
            if (isok(node[1]))
                return subtree_down_first(1, ide(), isok);
            return -1;
        }
        T lx = ide();
        int r = n << 1;
        l += n;
        while (l < r)
        {
            if (l & 1)
            {
                T next = ope(lx, node[l]);
                if (isok(next))
                    return subtree_down_first(l, lx, isok);
                lx = next;
                l++;
            }
            l >>= 1;
            r >>= 1;
        }
        return -1;
    } ///
};

int op(int x, int y) { return x + y; }
int ide() { return 0; }
using Seg = segment_tree<int, ide, op>;

bool solve()
{
    int N;
    std::cin >> N;
    if (N == 0)
        return false;
    int K;
    std::cin >> K;
    std::vector<double> X(N), Y(N);
    std::vector<double> Ys;
    for (int i = 0; i < N; i++)
    {
        std::cin >> X[i] >> Y[i];
        Ys.push_back(Y[i]);
    }
    std::sort(Ys.begin(), Ys.end());
    Ys.erase(std::unique(Ys.begin(), Ys.end()), Ys.end());

    double ans = 1e18;

    std::vector<std::tuple<double, int>> in, out;
    for (int i = 0; i < N; i++)
    {
        double h = Y[i] - 0;
        in.push_back({X[i] - h / std::sqrt(3), i});
        out.push_back({X[i] + h / std::sqrt(3), i});
    }
    std::sort(in.begin(), in.end());
    std::sort(out.begin(), out.end());
    std::vector<int> oi(N, -1);
    for (int i = 0; i < out.size(); i++)
    {
        oi[std::get<1>(out[i])] = i;
    }

    for (int b = 0; b < Ys.size(); b++)
    {
        int baseline = Ys[b];
        std::vector<int> init(out.size(), 0);
        for (int i = 0; i < N; i++)
        {
            if (Y[i] < baseline)
                continue;
            init[oi[i]] = 1;
        }
        Seg seg(init);
        for (auto [x, i] : in)
        {
            if (Y[i] < baseline)
                continue;
            int R = seg.find_first(0, [&](int s)
                                   { return s >= N - K; });
            if (R == -1)
                break;
            int j = std::get<1>(out[R - 1]);
            double r = X[j] + (Y[j] - baseline) / std::sqrt(3);
            double l = X[i] - (Y[i] - baseline) / std::sqrt(3);
            ans = std::min(ans, 3.0 * (r - l));
            seg.update(oi[i], 0);
        }
    }
    std::cout << ans << std::endl;
    return true;
}

int main()
{
    std::cout << std::setprecision(10) << std::fixed;
    while (solve())
        ;
}
accuracy: 1
time_ms: 5940
memory_kb: 4236
final_rank: 13

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

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#pragma GCC target("sse,sse2,sse3,sse4,ssse3,popcnt,abm,mmx,avx,tune=native")

using ll = long long;
using ld = long double;

mt19937 engine(42);

bool is_end = false;

const ld root3 = sqrtl((ld)3.0);

inline tuple<ld, ld, ld> convert_xy_to_pqr(ld x, ld y)
{
    return {y, root3 * x - y, -root3 * x - y};
}

inline pair<ld, ld> convert_pqr_to_xy(ld p, ld q, ld r)
{
    return {(p + q) / root3, p};
}

inline ld get_triangle_length(ld p, ld q, ld r)
{
    ld x0 = (p + q) / root3;
    ld x1 = - (p + r) / root3;
    return 3 * (x1 - x0);
}

template<class T>
bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0;}

void solve()
{
    int N, K; cin >> N >> K;
    if (N == 0)
    {
        is_end = true;
        return;
    }
    
    vector<tuple<ld, ld, ld>> tree(N);
    vector<vector<pair<ld, int>>> ord(3, vector<pair<ld, int>>(N));
    for (uint i = 0; i < N; ++i)
    {
        ld x, y; cin >> x >> y;
        ld ran = (ld)engine() / UINT_MAX;
        y += ran * 1e-11;
        auto [p, q, r] = tree[i] = convert_xy_to_pqr(x, y);
        
        ord[0][i] = {p, i};
        ord[1][i] = {q, i};
        ord[2][i] = {r, i};
    }
    for (uint j = 0; j < 3; ++j)
    {
        sort(ord[j].begin(), ord[j].end());
    }
    
    ld res = 1e18;
    vector<bool> isin(N, true);
    int outer = 0;
    for (uint i0 = 0; i0 <= K; ++i0)
    {
        auto [p, id0] = ord[0][i0];
        uint i2 = K;
        outer = 0;
        for (int j = 0; j <= K; ++j)
        {
            auto [r0, id0] = ord[0][j];
            auto [r1, id1] = ord[1][j];
            auto [r2, id2] = ord[1][j];
            isin[id0] = isin[id1] = isin[id2] = true;
        }
        
        for (uint j = 0; j < i0; ++j)
        {
            auto [r0, id0] = ord[0][j];
            isin[id0] = false, outer++;
        }
        for (uint j = 0; j < K; ++j)
        {
            auto [r, id2] = ord[2][j];
            if (isin[id2]) isin[id2] = false, outer++;
        }
        // cout << i0 << " " << outer << endl;
        
        for (uint i1 = 0; i1 <= K; ++i1)
        {
            auto [q, id1] = ord[1][i1];
            
            while (outer > K && i2 > 0)
            {
                --i2;
                auto [r, id2] = ord[2][i2];
                auto [p2, q2, r2] = tree[id2];
                if (p2 >= p && q2 >= q) isin[id2] = true, outer--;
            }
            
            if (outer > K) break;
            
            chmin(res, get_triangle_length(p, q, ord[2][i2].first));
            
            if (isin[id1]) isin[id1] = false, outer++;
        }
        
        // if (isin[id0]) isin[id0] = false, outer++;
    }
    
    cout << fixed << setprecision(20);
    cout << res << endl;
    
    return;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    while (!is_end)
    {
        solve();
    }
    
    return 0;
}
accuracy: 1
time_ms: 2820
memory_kb: 5096
final_rank: 10

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

#define ll long long

using D=double;
D s3=1.7320508075688772;

void solve(){
  int n,k;
  cin>>n;
  if(n==0)exit(0);
  cin>>k;
  int rem=n-k;
  vector<pair<int,int>>xy;
  vector<pair<D,int>>order;
  vector<pair<int,D>>iy;
  for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;
    iy.push_back({i,y});
    order.push_back({D(x)-D(y)/s3,i});
    xy.push_back({x,y});
  }
  sort(order.begin(),order.end());
  sort(iy.begin(),iy.end(),[](pair<int,D>A,pair<int,D>B){return A.second>B.second;});
  D ans=1<<30;
  vector<int>ok(n,0);
  for(int i=0;i<n;i++){
    priority_queue<D,vector<D>>pq;
    int idx=iy[i].first;
    D y_pos=iy[i].second;
    ok[idx]=1;
    for(int j=n-1;j>=0;j--){
      int idx2=order[j].second;
      if(ok[idx2]){
        auto [x,y]=xy[idx2];
        D L=D(x)-D(y-y_pos)/s3;
        D R=D(x)+D(y-y_pos)/s3;
        pq.push(R);
        if(pq.size()>rem)pq.pop();
        if(pq.size()==rem)ans=min(ans,pq.top()-L);
      }
    }
  }
  cout<<fixed<<setprecision(15)<<ans*3<<'\n';
}

int main(){
  while(1)solve();
}
accuracy: 1
time_ms: 7840
memory_kb: 4180
final_rank: 16

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

int main() {
	while (true) {
		// step #1. input
		int N;
		cin >> N;
		if (N == 0) {
			break;
		}
		int K;
		cin >> K;
		vector<int> X(N), Y(N);
		for (int i = 0; i < N; i++) {
			cin >> X[i] >> Y[i];
		}

		// step #2. preparation
		const double SQRT3 = sqrt(3);
		K = N - K;
		vector<int> comps = Y;
		sort(comps.begin(), comps.end());
		comps.erase(unique(comps.begin(), comps.end()), comps.end());
		vector<double> z1(N), z2(N);
		vector<int> p1(N), p2(N);
		for (int i = 0; i < N; i++) {
			z1[i] = X[i] * SQRT3 - Y[i];
			z2[i] = X[i] * SQRT3 + Y[i];
			p1[i] = i;
			p2[i] = i;
		}
		sort(p1.begin(), p1.end(), [&](int va, int vb) { return z1[va] < z1[vb]; });
		sort(p2.begin(), p2.end(), [&](int va, int vb) { return z2[va] < z2[vb]; });
		vector<int> inv1(N), inv2(N);
		for (int i = 0; i < N; i++) {
			inv1[p1[i]] = i;
			inv2[p2[i]] = i;
		}
		
		// step #3. search
		double ans = 1.0e+99;
		for (int border : comps) {
			int cnt = 0, pos = -1;
			for (int i = 0; i < N; i++) {
				while (pos != N - 1 && cnt < K) {
					pos += 1;
					if (Y[p2[pos]] >= border && inv1[p2[pos]] >= i) {
						cnt += 1;
					}
				}
				if (cnt >= K) {
					double v1 = z1[p1[i]];
					double v2 = z2[p2[pos]];
					double x1 = (v1 + border) / SQRT3;
					double x2 = (v2 - border) / SQRT3;
					ans = min(ans, (x2 - x1) * 3);
				}
				if (Y[p1[i]] >= border && inv2[p1[i]] <= pos) {
					cnt -= 1;
				}
			}
		}

		// step #4. output
		cout.precision(15);
		cout << fixed << ans << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 2210
memory_kb: 3772
final_rank: 5

code_snippet: #include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int N;
int K;
int X[1 << 18], Y[1 << 18];

int main() {
	while (true) {
		// Step 1. Input
		cin >> N; if (N == 0) break;
		cin >> K;
		for (int i = 1; i <= N; i++) cin >> X[i] >> Y[i];

		// Step 2. Sorting
		double SQRT3 = sqrt(3.0);
		vector<pair<double, int>> L;
		vector<pair<double, int>> R;
		for (int i = 1; i <= N; i++) L.push_back(make_pair(SQRT3 * X[i] - 1.0 * Y[i], i));
		for (int i = 1; i <= N; i++) R.push_back(make_pair(SQRT3 * X[i] + 1.0 * Y[i], i));
		sort(L.begin(), L.end());
		sort(R.begin(), R.end());

		// Step 3. Enumerate Zahyou
		vector<int> Zahyou;
		for (int i = 1; i <= N; i++) Zahyou.push_back(Y[i]);
		sort(Zahyou.begin(), Zahyou.end());
		Zahyou.erase(unique(Zahyou.begin(), Zahyou.end()), Zahyou.end());

		// Step 4. Brute Force
		double Answer = 1.0e12;
		for (int pts : Zahyou) {
			int cur = 0, cnt = 0;
			for (int j = 0; j < L.size(); j++) {
				double Border = L[j].first;

				// Shakutorization
				while (cur < R.size() && cnt < N - K) {
					int idx = R[cur].second;
					if (Y[idx] >= pts && SQRT3 * X[idx] - 1.0 * Y[idx] >= Border) cnt += 1;
					cur += 1;
				}
				if (cnt < N - K) break;

				// Get Answer
				double cl = (L[j].first + 1.0 * pts) / SQRT3;
				double cr = (R[cur - 1].first - 1.0 * pts) / SQRT3;
				Answer = min(Answer, 3.0 * (cr - cl));

				// Refresh
				int idx = L[j].second;
				if (Y[idx] >= pts && SQRT3 * X[idx] + 1.0 * Y[idx] <= R[cur - 1].first) cnt -= 1;
			}
		}

		// Step 5. Output
		printf("%.12lf\n", Answer);
	}
	return 0;
}
accuracy: 1
time_ms: 1620
memory_kb: 3904
final_rank: 3

code_snippet: #include <string.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <ciso646>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP_OVERLOAD(arg1, arg2, arg3, arg4, NAME, ...) NAME
#define REP3(i, l, r, s)                                               \
    for (int i = int(l), rep3_r = int(r), rep3_s = int(s); i < rep3_r; \
         i += rep3_s)
#define REP2(i, l, r) REP3(i, l, r, 1)
#define REP1(i, n) REP2(i, 0, n)
#define rep(...) REP_OVERLOAD(__VA_ARGS__, REP3, REP2, REP1, )(__VA_ARGS__)
#define repin(i, l, r) for (int i = int(l), repin_r = int(r); i <= repin_r; ++i)

#define RREP_OVERLOAD(arg1, arg2, arg3, arg4, NAME, ...) NAME
#define RREP3(i, l, r, s)                                                      \
    for (int i = int(r) - 1, rrep3_l = int(l), rrep3_s = int(s); i >= rrep3_l; \
         i -= rrep3_s)
#define RREP2(i, l, r) RREP3(i, l, r, 1)
#define RREP1(i, n) RREP2(i, 0, n)
#define rrep(...) RREP_OVERLOAD(__VA_ARGS__, RREP3, RREP2, RREP1, )(__VA_ARGS__)
#define rrepin(i, l, r) \
    for (int i = int(r), rrepin_l = int(l); i >= rrepin_l; --i)

#define fi first
#define se second


#include <algorithm>
#include <cassert>
#include <vector>

namespace rklib {

// a <- max(a, b)
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

// a <- min(a, b)
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

// if a < 0: a <- b
// else: a <- min(a, b)
template <class T>
bool chmin_non_negative(T &a, const T &b) {
    if (a < 0 || a > b) {
        a = b;
        return true;
    }
    return false;
}

// floor(num / den)
template <class T>
T div_floor(T num, T den) {
    if (den < 0) num = -num, den = -den;
    return num >= 0 ? num / den : (num + 1) / den - 1;
}

// ceil(num / den)
template <class T>
T div_ceil(T num, T den) {
    if (den < 0) num = -num, den = -den;
    return num <= 0 ? num / den : (num - 1) / den + 1;
}

namespace internal {

template <class T>
T remainder_count(T r, T b, T m) {
    return r / m * b + std::min(b, r % m);
}

}  // namespace internal

// Number of integer x s.t.
// - x in [l, r)
// - x mod m in [a, b)
template <class T>
T remainder_count(T l, T r, T a, T b, T m) {
    assert(l >= 0);
    assert(m >= 1);

    if (l >= r || a >= b) return 0;
    if (m <= a || b < 0) return 0;
    chmax(a, T(0));
    chmin(b, m);

    auto res = internal::remainder_count(r, b, m);
    if (l >= 1) res -= internal::remainder_count(l, b, m);
    if (a >= 1) res -= internal::remainder_count(r, a, m);
    if (l >= 1 && a >= 1) res += internal::remainder_count(l, a, m);

    return res;
}

}  // namespace rklib


using namespace std;
using namespace rklib;

using lint = long long;
using pii = pair<int, int>;
using pll = pair<lint, lint>;

int main() {
    while (true) {
        int n, K;
        cin >> n;
        if (n == 0) break;
        cin >> K;
        vector<double> x(n), y(n);
        rep(i, n) cin >> x[i] >> y[i];

        vector<int> lps(n), rps(n);
        iota(lps.begin(), lps.end(), 0);
        iota(rps.begin(), rps.end(), 0);
        sort(lps.begin(), lps.end(), [&](const int &i, const int &j) {
            return x[i] * sqrt(3) - y[i] < x[j] * sqrt(3) - y[j];
        });
        sort(rps.begin(), rps.end(), [&](const int &i, const int &j) {
            return x[i] * sqrt(3) + y[i] < x[j] * sqrt(3) + y[j];
        });

        double ans = 1e9;
        for (auto ty : y) {
            vector<bool> used(n, false);
            int cnt = 0;
            int r = 0;

            for (auto l_id : lps) {
                while (r < n && cnt < n - K) {
                    int r_id = rps[r];
                    if (!used[r_id] && y[r_id] >= ty) {
                        used[r_id] = true;
                        ++cnt;
                    }
                    ++r;
                }
                if (cnt >= n - K) {
                    double lx = x[l_id] + (ty - y[l_id]) / sqrt(3);
                    int r_id = rps[r - 1];
                    double rx = x[r_id] + (y[r_id] - ty) / sqrt(3);
                    chmin(ans, (rx - lx) * 3);
                } else {
                    break;
                }

                if (used[l_id]) {
                    --cnt;
                }
                used[l_id] = true;
            }
        }
        printf("%.10lf\n", ans);
    }
}
accuracy: 1
time_ms: 2870
memory_kb: 3656
final_rank: 6

code_snippet: #include <bits/stdc++.h>

#define rep(i,s,n) for(int i = int(s); i < int(n); i++)
#define rrep(i,s,n) for(int i = int(n) - 1; i >= s; i--)
#define all(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using ld = long double;

template<class T>
bool chmin(T &a, T b) {
    if(a <= b) return false;
    a = b;
    return true;
}
template<class T>
bool chmax(T &a, T b) {
    if(a >= b) return false;
    a = b;
    return true;
}

using namespace std;

const ld dinf = 2e9;
const ld r3 = ld(1)/sqrtl(3);

int main() {
    cout << fixed << setprecision(15);
    while (true){
        int n; cin >> n;
        if (n == 0) break;
        int k; cin >> k;
        vector<int> xs(n), ys(n);
        rep(i,0,n) cin >> xs[i] >> ys[i];
        vector<int> idl(n); iota(all(idl),0);
        sort(all(idl),[&](int i, int j){
            int ai = xs[i], bi = -ys[i];
            int aj = xs[j], bj = -ys[j];
            int lhs = bi-bj, rhs = aj-ai;
            if (lhs < 0 && rhs > 0) return true;
            if (lhs > 0 && rhs < 0) return false;
            if (lhs >= 0 && rhs >= 0){
                return lhs*lhs < 3*rhs*rhs;
            }
            return 3*rhs*rhs < lhs*lhs;
        });
        vector<int> idr(n); iota(all(idr),0);
        sort(all(idr),[&](int i, int j){
            int ai = xs[i], bi = +ys[i];
            int aj = xs[j], bj = +ys[j];
            int lhs = bi-bj, rhs = aj-ai;
            if (lhs < 0 && rhs > 0) return true;
            if (lhs > 0 && rhs < 0) return false;
            if (lhs >= 0 && rhs >= 0){
                return lhs*lhs < 3*rhs*rhs;
            }
            return 3*rhs*rhs < lhs*lhs;
        });
        vector<int> vl(n), vr(n);
        rep(i,0,n){
            vl[idl[i]] = i;
            vr[idr[i]] = i;
        }
        ld ans = dinf;
        for (int y : ys){
            int cnt = 0;
            int r = 0;
            rep(i,0,n){
                while (r < n && cnt < n-k){
                    int id = idr[r];
                    if (ys[id] >= y && vl[id] >= i) cnt++;
                    r++;
                }
                if (cnt >= n-k){
                    int il = idl[i], ir = idr[r-1];
                    ld cur = (xs[ir] + (ys[ir]-y)*r3) - (xs[il] - (ys[il]-y)*r3);
                    chmin(ans,cur);
                }
                int id = idl[i];
                if (ys[id] >= y && vr[id] < r) cnt--;
            }
        }
        cout << 3*ans << endl;
    }
}
accuracy: 1
time_ms: 3640
memory_kb: 3604
final_rank: 8

code_snippet: #pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

const double sqrt3 = 1.0/sqrt(3);

struct point{
    int x,y;
    point() {}
    point(int x,int y): x(x), y(y) {}
};

vector<pair<double,int>> lv,rv;
bool ld[10000], rd[10000];
bool done[10000];

double solve(int n){
    int k; cin >> k;
    vector<point> p(n);
    vector<int> p_idx(n);
    lv.resize(n);
    rv.resize(n);
    for(int i=0;i<n;i++){
        cin >> p[i].x >> p[i].y;
        p_idx[i] = i;
        done[i] = false;
        lv[i] = {-p[i].y*sqrt3+p[i].x,i}; // y*sqrt3
        rv[i] = {p[i].y*sqrt3+p[i].x,i}; // -y*sqrt3
    }
    sort(lv.begin(), lv.end());
    sort(rv.begin(), rv.end());
    lv.push_back({1e9,-1});
    rv.push_back({1e9,-1});
    sort(p_idx.begin(), p_idx.end(), [&](auto i,auto j){
        return p[i].y < p[j].y;
    });
    int need = n-k;
    double res = 1e9;
    for(int i=0;i<=k;){
        int y = p[p_idx[i]].y;

        for(int j=0;j<n;j++){
            if(!done[j]) ld[j] = rd[j] = false;
        }

        int r1 = 0;
        int r2 = 0;
        int cnt = 0;
        const double lad = sqrt3*y;
        const double rad = -sqrt3*y;
        for(int l1=0;l1<n;l1++){
            while(r2<n and cnt < need){
                if(lv[r1].first+lad <= rv[r2].first+rad){
                    int id = lv[r1].second;
                    if(!done[id]){
                        ld[id] = true;
                        if(rd[id]) cnt++;
                    }
                    r1++;
                }
                else{
                    int id = rv[r2].second;
                    if(!done[id]){
                        rd[id] = true;
                        if(ld[id])cnt++;
                    }
                    r2++;
                }
            }
            if(cnt == need){
                res = min(res, rv[r2-1].first-lv[l1].first-lad+rad);
            }
            else break;
            ld[lv[l1].second] = false;
            if(rd[lv[l1].second]){
                rd[lv[l1].second] = false;
                cnt--;
            }
        }

        while(i<n and p[p_idx[i]].y == y){
            done[p_idx[i]] = true;
            i++;
        }
    }
    return res*3;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n,n){
        printf("%.9f\n",solve(n));
    }
}
accuracy: 1
time_ms: 4010
memory_kb: 3772
final_rank: 9

code_snippet: #include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::mt19937 rnd;
int rnd_int(int l, int r) {
	return std::uniform_int_distribution<>(l, r)(rnd);
}

bool solve() {
	int n = ri();
	if (n == 0) return false;
	int k = ri();
	struct Point {
		int a;
		double b;
		double c;
	};
	std::vector<Point> points;
	// std::set<std::pair<int, int> > used;
	for (int i = 0; i < n; i++) {
		/*
		int x, y;
		do {
			x = rnd_int(-10000, 10000);
			y = rnd_int(-10000, 10000);
		} while (!used.insert({x, y}).second);*/
		int x = ri();
		int y = ri();
		points.push_back({y, (double) y / 2 - sqrt(3) * x / 2, (double) y / 2 + sqrt(3) * x / 2});
	}
	clock_t r0 = clock();
	std::sort(points.begin(), points.end(), [] (auto &i, auto &j) { return i.a > j.a; });
	std::map<double, double> bc;
	std::map<double, double> cb;
	int added = 0;
	double res = 1000000000;
	for (auto pt : points) {
		assert(!bc.count(pt.b));
		assert(!cb.count(pt.c));
		bc[pt.b] = pt.c;
		cb[pt.c] = pt.b;
		added++;
		if (added >= n - k) {
			auto itr1 = bc.begin();
			auto itr2 = cb.rbegin();
			// assert(itr2 != cb.rend());
			double b_limit = -1000000000;
			double c_limit = itr2->first;
			int cur = 0;
			while (itr1 != bc.end() && cur < n - k) {
				cur++;
				b_limit = itr1->first;
				itr1++;
			}
			auto shakutori = [&] () {
				while (cur >= n - k && itr2 != cb.rend() && (cur > n - k || itr2->second > b_limit)) {
					if (itr2->second <= b_limit) cur--;
					itr2++;
					// assert(itr2 != cb.rend());
					c_limit = itr2->first;
				}
			};
			shakutori();
			// assert(itr1 != bc.begin());
			double min = b_limit + c_limit;
			while (itr1 != bc.end()) {
				if (itr1->second <= c_limit) cur++;
				b_limit = itr1->first;
				itr1++;
				shakutori();
				min = std::min(min, b_limit + c_limit);
			}
			res = std::min(res, min - pt.a);
		}
	}
	clock_t r1 = clock();
	printf("%.11f\n", res * sqrt(3) * 2);
	// fprintf(stderr, "%.2f ms\n", (double)(r1 - r0) / CLOCKS_PER_SEC * 1000);
	return true;
}
int main() {
	while (1) {
		bool cont = solve();
		if (!cont) break;
	}
	return 0;
}
accuracy: 1
time_ms: 6470
memory_kb: 4828
final_rank: 15

code_snippet: #include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

std::mt19937 rnd;
int rnd_int(int l, int r) {
	return std::uniform_int_distribution<>(l, r)(rnd);
}

bool solve() {
	int n = ri();
	if (n == 0) return false;
	int k = ri();
	struct Point {
		int a;
		double b;
		double c;
	};
	std::vector<Point> points;
	// std::set<std::pair<int, int> > used;
	for (int i = 0; i < n; i++) {
		/*
		int x, y;
		do {
			x = rnd_int(-10000, 10000);
			y = rnd_int(-10000, 10000);
		} while (!used.insert({x, y}).second);*/
		int x = ri();
		int y = ri();
		points.push_back({y, (double) y / 2 - sqrt(3) * x / 2, (double) y / 2 + sqrt(3) * x / 2});
	}
	clock_t r0 = clock();
	std::sort(points.begin(), points.end(), [] (auto &i, auto &j) { return i.a > j.a; });
	std::map<double, double> bc;
	std::map<double, double> cb;
	int added = 0;
	double res = 1000000000;
	for (auto pt : points) {
		bc[pt.b] = pt.c;
		cb[pt.c] = pt.b;
		added++;
		if (added >= n - k) {
			auto itr1 = bc.begin();
			auto itr2 = cb.rbegin();
			// assert(itr2 != cb.rend());
			double b_limit = -1000000000;
			double c_limit = itr2->first;
			int cur = 0;
			while (itr1 != bc.end() && cur < n - k) {
				cur++;
				b_limit = itr1->first;
				itr1++;
			}
			// assert(itr1 != bc.begin());
			double min = b_limit + c_limit;
			while (itr1 != bc.end()) {
				if (itr1->second <= c_limit) cur++;
				b_limit = itr1->first;
				itr1++;
				while (cur >= n - k && itr2 != cb.rend() && (cur > n - k || itr2->second > b_limit)) {
					if (itr2->second <= b_limit) cur--;
					itr2++;
					// assert(itr2 != cb.rend());
					c_limit = itr2->first;
				}
				min = std::min(min, b_limit + c_limit);
			}
			res = std::min(res, min - pt.a);
		}
	}
	clock_t r1 = clock();
	printf("%.11f\n", res * sqrt(3) * 2);
	// fprintf(stderr, "%.2f ms\n", (double)(r1 - r0) / CLOCKS_PER_SEC * 1000);
	return true;
}
int main() {
	while (1) {
		bool cont = solve();
		if (!cont) break;
	}
	return 0;
}
accuracy: 0.5
time_ms: 6450
memory_kb: 4832
final_rank: 20

code_snippet: #include <bits/stdc++.h>

using namespace std;

struct point
{
    double x,y;
};

void chmin(double &x, double y)
{
    if(x>y) x=y;
}

constexpr double sq3=sqrt(3);

void solve()
{
    int n,k; cin>>n;
    if(!n) exit(0);
    cin>>k;
    k=n-k;
    vector<point> pnt(n);

    for(point &e:pnt)
    {
        cin>>e.x>>e.y;
    }
    sort(begin(pnt), end(pnt),
    [](point p1, point p2)
    {
        if(p1.y==p2.y)
        {
            return p1.x>p2.x;
        }
        return p1.y>p2.y;
    });

    struct left_comp
    {
        bool operator()(point p1, point p2)
        {
            return p2.y-sq3*p2.x>p1.y-sq3*p1.x;
        }
    };
    auto lpnt=pnt;
    sort(begin(lpnt),end(lpnt), left_comp());

    struct right_comp
    {
        bool operator()(point p1, point p2)
        {
            return p2.y+sq3*p2.x>p1.y+sq3*p1.x;
        }
    };
    auto rpnt=pnt;

    sort(begin(rpnt), end(rpnt), right_comp());

    double ans=1e5;

    for(auto i=begin(pnt),j=i; i!=end(pnt); i=j)
    {
        const double nowy=i->y;
        vector<point> clf,crg;
        for(auto &p: lpnt)
        {
            if(p.y>=nowy) clf.emplace_back(p);
        }
        // for(auto &p: rpnt)
        // {
        //     if(p.y>=nowy) crg.emplace_back(p);
        // }
        // auto itr=end(crg);
        priority_queue<point,vector<point>,right_comp> que;

        for(const auto &p: clf)
        {
                // cerr << "p: " << p.x << " " << p.y << endl;

            if(que.size()<k || right_comp()(p,que.top()))
            {
                que.emplace(p);
            }
            if(que.size()>k) que.pop();
            if(que.size()==k) // update
            {
                const double lx=p.x-(p.y-nowy)/sq3;
                auto tp=que.top();
                const double rx=tp.x+(tp.y-nowy)/sq3;
                // cerr << nowy << endl;
                // cerr << "p: " << p.x << " " << p.y << endl;
                // cerr << "tp: " << tp.x << " " << tp.y << endl;
                chmin(ans, rx-lx);
            }
        }

        while(j!=end(pnt) && i->y==j->y) ++j;
    }

    cout << fixed << setprecision(10) << ans*3 << "\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(true) solve();
}
accuracy: 1
time_ms: 5670
memory_kb: 4240
final_rank: 12

code_snippet: #pragma GCC ta g("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
//#include <atcoder/maxflow>
//using namespace atcoder;
const int inf = (1<<30)-1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-9;
//const int mod = 1e9 + 7;
const int mod = 998244353;

int main(){
	while(1){
		int n; cin >> n;
		if(!n) break;
		int k; cin >> k;
		vector<pii> p(n);
		rep(i,n) cin >> p[i].first >> p[i].second;
		sort(all(p),[](pii a, pii b){
			if(sqrt(3)*a.first+a.second == sqrt(3)*b.first+b.second){
				return a.first < b.first;
			}
			return sqrt(3)*a.first+a.second <= sqrt(3)*b.first+b.second;}
		);
		auto L = [](pii a, pii b) -> bool {
			return -sqrt(3)*a.first+a.second <= -sqrt(3)*b.first+b.second + eps;
		};
		auto R = [](pii a, pii b) -> bool {
			return sqrt(3)*a.first+a.second <= sqrt(3)*b.first+b.second + eps;
		};
		vector<int> v(10101,0);
		double ans = inf;
		rep(i,n){
			int now = 0;
			int bottom = 1;
			int cnt = 0;
			rep(j,n){
				if(now <= j && R(p[now],p[j])){
					if(L(p[now],p[i]) && p[now].second >= bottom){
						v[p[now].second]++;
						cnt++;
					}
					now++;
				}
				double C = -sqrt(3)*p[i].first + p[i].second;
				double D = sqrt(3)*p[j].first + p[j].second;
				while(cnt >= n-k){
					double x1 = (bottom-C)/sqrt(3);
					double x2 = (D-bottom)/sqrt(3);
					chmin(ans,x2-x1);
					if(cnt - v[bottom] < n-k) break;
					cnt -= v[bottom];
					v[bottom] = 0;
					bottom++;
				}
			}
			REP(i,bottom,10100) v[i] = 0;
		}
		printf("%.10f\n",ans*3);
	}
}
accuracy: 1
time_ms: 3190
memory_kb: 3660
final_rank: 7