Problem:
Problem Statement
We have planted $N$ flower seeds, all of which come into different flowers.
We want to make all the flowers come out together.
Each plant has a value called vitality, which is initially zero.
Watering and spreading fertilizers cause changes on it, and the $i$-th plant will come into flower if its vitality is equal to or greater than $\mathit{th}_i$.
Note that $\mathit{th}_i$ may be negative because some flowers require no additional nutrition.
Watering effects on all the plants.
Watering the plants with $W$ liters of water changes the vitality of the $i$-th plant by $W \times \mathit{vw}_i$ for all $i$ ($1 \le i \le n$), and costs $W \times \mathit{pw}$ yen, where $W$ need not be an integer.
$\mathit{vw}_i$ may be negative because some flowers hate water.
We have $N$ kinds of fertilizers, and the $i$-th fertilizer effects only on the $i$-th plant.
Spreading $F_i$ kilograms of the $i$-th fertilizer changes the vitality of the $i$-th plant by $F_i \times \mathit{vf}_i$, and costs $F_i \times \mathit{pf}_i$ yen, where $F_i$ need not be an integer as well.
Each fertilizer is specially made for the corresponding plant, therefore $\mathit{vf}_i$ is guaranteed to be positive.
Of course, we also want to minimize the cost.
Formally, our purpose is described as "to minimize $W \times \mathit{pw} + \sum_{i=1}^{N}(F_i \times \mathit{pf}_i)$ under $W \times \mathit{vw}_i + F_i \times \mathit{vf}_i \ge \mathit{th}_i$, $W \ge 0$, and $F_i \ge 0$ for all $i$ ($1 \le i \le N$)".
Your task is to calculate the minimum cost.
Input
The input consists of multiple datasets.
The number of datasets does not exceed $100$, and the data size of the input does not exceed $20\mathrm{MB}$.
Each dataset is formatted as follows.
$N$
$\mathit{pw}$
$\mathit{vw}_1$ $\mathit{pf}_1$ $\mathit{vf}_1$ $\mathit{th}_1$
:
:
$\mathit{vw}_N$ $\mathit{pf}_N$ $\mathit{vf}_N$ $\mathit{th}_N$
The first line of a dataset contains a single integer $N$, number of flower seeds.
The second line of a dataset contains a single integer $\mathit{pw}$, cost of watering one liter.
Each of the following $N$ lines describes a flower. The $i$-th line contains four integers, $\mathit{vw}_i$, $\mathit{pf}_i$, $\mathit{vf}_i$, and $\mathit{th}_i$, separated by a space.
You can assume that $1 \le N \le 10^5$, $1 \le \mathit{pw} \le 100$, $-100 \le \mathit{vw}_i \le 100$, $1 \le \mathit{pf}_i \le 100$, $1 \le \mathit{vf}_i \le 100$, and $-100 \le \mathit{th}_i \le 100$.
The end of the input is indicated by a line containing a zero.
Output
For each dataset, output a line containing the minimum cost to make all the flowers come out.
The output must have an absolute or relative error at most $10^{-4}$.
Sample Input
3
10
4 3 4 10
5 4 5 20
6 5 6 30
3
7
-4 3 4 -10
5 4 5 20
6 5 6 30
3
1
-4 3 4 -10
-5 4 5 -20
6 5 6 30
3
10
-4 3 4 -10
-5 4 5 -20
-6 5 6 -30
0
Output for the Sample Input
43.5
36
13.5
0

Submitted solutions:

code_snippet: #include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define ll __int64
#define eps 1e-10
int sig(double x)
{
    return (x>eps)-(x<-eps);
}
const int N=1e5+10;
int pw,vw[N],pf[N],vf[N],th[N];
int n;
double judge(double w)
{
    double ans=w*pw;
    for(int i=0;i<n;i++)
    {
        double f;
        if(sig(w*vw[i]-th[i])>=0) f=0;
        else
        f=(th[i]-w*vw[i])/(double)vf[i];
        ans+=f*pf[i];
    }
    return ans;
}
int main()
{
    while(scanf("%d",&n)!=EOF&&n)
    {
        scanf("%d",&pw);
        for(int i=0;i<n;i++)
        {
            scanf("%d%d%d%d",&vw[i],&pf[i],&vf[i],&th[i]);
        }
        double l=0,r=100000;
        while(l+eps<r)
        {
            double m1=l+(r-l)/3,m2=r-(r-l)/3;
            double need1=judge(m1);
            double need2=judge(m2);
            //printf("%lf %lf %lf %lf\n",m1,need1,m2,need2);
            if(sig(need1-need2)>=0) l=m1+eps;
            else r=m2-eps;
        }
        //printf("%lf\n",l);
        double ans=judge(l);
        printf("%.6lf\n",ans);
    }
    return 0;
}
accuracy: 1
time_ms: 620
memory_kb: 5048
final_rank: 2

code_snippet: #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define rep(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)
#define drep(i, m, n) for (ll i = m - 1; i >= n; i--)
#define Endl endl
#define all(a) a.begin(), a.end()
#define pr(i, j) make_pair(i, j)
#define isin(x, l, r) (l <= x && x < r)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define srt(ar) sort(ar.begin(), ar.end())
#define rev(ar) reverse(ar.begin(), ar.end())
#define jge(f, s, t) cout << (f ? s : t) << endl
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define printar(ar)             \
    do                          \
    {                           \
        for (auto dbg : ar)     \
        {                       \
            cout << dbg << " "; \
        }                       \
        cout << endl;           \
    } while (0)
const ll inf = 1e18;
const ld pi = 3.14159265358979;
const ld eps = 1e-9;
template <class T, ll n, ll idx = 0>
auto make_vec(const ll (&d)[n], const T &init) noexcept
{
    if constexpr (idx < n)
        return std::vector(d[idx], make_vec<T, n, idx + 1>(d, init));
    else
        return init;
}

template <class T, ll n>
auto make_vec(const ll (&d)[n]) noexcept
{
    return make_vec(d, T{});
}
//////////////// 以下を貼る ////////////////
template <class T>
size_t HashCombine(const size_t seed, const T &v)
{
    return seed ^ (std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
}
/* pair用 */
template <class T, class S>
struct std::hash<std::pair<T, S>>
{
    size_t operator()(const std::pair<T, S> &keyval) const noexcept
    {
        return HashCombine(std::hash<T>()(keyval.first), keyval.second);
    }
};
////////////////////////////////////////////
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    while (true)
    {
        ll n;
        cin >> n;
        if (n == 0)
        {
            break;
        }
        ld W;
        cin >> W;
        vector<ld> a, b, c, d;
        ld sub = 0;
        ld A = W;
        ld B = 0;
        vector<ld> T;
        vector<ld> C, D;
        vector<pair<ld, ll>> E;
        ll N = 0;
        rep(i, 0, n)
        {
            ld s, t, u, v;
            cin >> s >> t >> u >> v;
            if (s == 0)
            {
                if (v >= 0)
                {
                    sub += v * t / u;
                }
            }
            else if (s < 0)
            {
                if (v >= 0)
                {
                    A += -s * t / u;
                    B += v * t / u;
                }
                else
                {
                    C.push_back(-s * t / u);
                    D.push_back(v * t / u);
                    E.push_back(pr(v / s, N));
                    T.push_back(1);
                    N++;
                }
            }
            else if (v <= 0)
            {
                continue;
            }
            else
            {
                A += -s * t / u;
                B += v * t / u;
                C.push_back(-s * t / u);
                D.push_back(v * t / u);
                E.push_back(pr(v / s, N));
                T.push_back(2);
                N++;
            }
        }
        ld ans = B + sub;
        srt(E);
        rep(i, 0, N - 1)
        {
            ld L = E[i].first;
            ld R = E[i + 1].first;
            ll idx = E[i].second;
            if (T[idx] == 1)
            {
                A += C[idx];
                B += D[idx];
            }
            else
            {
                A -= C[idx];
                B -= D[idx];
            }
            ld sub2 = min(A * L, A * R) + B;
            chmin(ans, sub + sub2);
        }
        cout << setprecision(15) << fixed << ans << endl;
    }
}
accuracy: 1
time_ms: 570
memory_kb: 16692
final_rank: 19

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() {
while(1) {
    int N;
    double A;
    cin >> N;
    if (N == 0) return 0;
    cin >> A;
    vector<double> B(N), C(N), D(N), E(N);
    rep(i,0,N) cin >> B[i] >> C[i] >> D[i] >> E[i];
    auto Calc = [&](double X) -> double {
        double SUM = X * A;
        rep(i,0,N) {
            double F = max(0.0, (E[i]-X*B[i])/D[i]);
            SUM += F * C[i];
        }
        return SUM;
    };
    double L = 0.0, R = INF;
    while(R-L > 0.0000000000001) {
        double M1 = (L*2.0+R*1.0)/3.0, M2 = (L*1.0+R*2.0)/3.0;
        if (Calc(M1) > Calc(M2)) L = M1;
        else R = M2;
    }
    printf("%.12f\n", Calc(L));
}
}
accuracy: 1
time_ms: 1540
memory_kb: 6380
final_rank: 12

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() {
while(1) {
    int N;
    double A;
    cin >> N;
    if (N == 0) return 0;
    cin >> A;
    vector<double> B(N), C(N), D(N), E(N);
    rep(i,0,N) cin >> B[i] >> C[i] >> D[i] >> E[i];
    auto Calc = [&](double X) -> double {
        double SUM = X * A;
        rep(i,0,N) {
            double F = max(0.0, (E[i]-X*B[i])/D[i]);
            SUM += F * C[i];
        }
        return SUM;
    };
    double L = 0.0, R = INF;
    while(R-L > 0.000000001) {
        double M1 = (L*2.0+R*1.0)/3.0, M2 = (L*1.0+R*2.0)/3.0;
        if (Calc(M1) > Calc(M2)) L = M1;
        else R = M2;
    }
    printf("%.12f\n", Calc((L+R)/2.0));
}
}
accuracy: 1
time_ms: 1480
memory_kb: 6356
final_rank: 11

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

const int maxn = 100005;
const double eps = 1e-12;

struct node {
    double vw, pf, vf, th;
} p[maxn];

int n;
double pw;

double calc(double W) {
    double ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (p[i].vw * W >= p[i].th) continue;
        ans += (p[i].th - p[i].vw * W) / p[i].vf * p[i].pf;
    }
    return ans + pw * W;
}

int main() {
    ios::sync_with_stdio(0);
    while (cin >> n && n) {
        cin >> pw;
        for (int i = 1; i <= n; ++i) {
            cin >> p[i].vw >> p[i].pf >> p[i].vf >> p[i].th;
        }
        double l = 0, r = 1000000000.0;
        while (r - l > eps) {
            double mid1 = l + (r - l) / 3, mid2 = r - (r - l) / 3;
            if (calc(mid1) < calc(mid2)) r = mid2;
            else l = mid1;
        }
        cout << fixed << setprecision(10) << calc(l) << '\n';
    }
}
accuracy: 1
time_ms: 1080
memory_kb: 6372
final_rank: 9

code_snippet: #line 2 "cp-library/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template < class T, class U > T ceil (T x, U y) { return (x > 0 ? (x + y - 1) / y :           x / y); }
template < class T, class U > T floor(T x, U y) { return (x > 0 ?           x / y : (x - y + 1) / y); }
int popcnt(i32 x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }

#line 2 "cp-library/src/utility/rep_itr.hpp"
template < class T > struct itr_rep {
    T i, d;
    constexpr itr_rep(const T i) noexcept : i(i), d(1) {}
    constexpr itr_rep(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr_rep x) const noexcept { return d > 0 ? i < x.i : i > x.i; }
};

template < class T > struct rep {
    const itr_rep< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};

template < class T > struct revrep {
    const itr_rep < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};
#line 3 "cp-library/src/utility/io.hpp"

/* 128bit integer */
istream& operator>>(istream& is, i128& x) {
    std::string s; is >> s;
    int pm = (s[0] == '-');
    x = 0;
    for(int i : rep(pm, int(s.size()))) x = x * 10 + (s[i] - '0');
    if(pm) x *= -1;
    return is;
}
ostream& operator<<(ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x;
    if(y < 0) { os << '-'; y *= -1; }
    std::vector<int> ny;
    while(y > 0) { ny.push_back(y % 10); y /= 10; }
    for(int i : revrep(ny.size())) os << ny[i];
    return os;
}

template < class S, class T > istream& operator>>(istream& is,       std::pair< S, T >& x) { is >> x.first        >> x.second; return is; }
template < class S, class T > ostream& operator<<(ostream& os, const std::pair< S, T >& x) { os << x.first << " " << x.second; return os; }

namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; std::cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator std::vector< T >() {
            std::vector< T > v(n);
            for(T& x : v) std::cin >> x;
            return v;
        }
    };
    struct mat {
        int h, w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator std::vector< std::vector< T > >() {
            std::vector m(h, std::vector< T >(w));
            for(std::vector< T >& v : m) for(T& x : v) std::cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            std::cin.tie(0);
            std::ios::sync_with_stdio(0);
        }
    } speedup_instance;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) { std::cout << std::fixed << std::setprecision(d); }
    void flush() { std::cout.flush(); }
}

template < class T >
ostream& operator<<(ostream& os, const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) { os << a[i]; if(i != n - 1) os << ' '; }
    return os;
}

int print() { std::cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    std::cout << h; if(sizeof...(tail)) std::cout << ' ';
    return print(std::forward<tail>(t)...);
}
template < class T > int print_n(const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) std::cout << a[i] << "\n";
    return 0;
}


#line 2 "cp-library/src/utility/key_val.hpp"

template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
    template < std::size_t Index >
    std::tuple_element_t< Index, key_val >& get() {
        if constexpr (Index == 0) return key;
        if constexpr (Index == 1) return val;
    }
};

namespace std {

template < class K, class V > struct tuple_size < key_val< K, V > > : integral_constant< size_t, 2 > {};
template < class K, class V > struct tuple_element < 0, key_val< K, V > > { using type = K; };
template < class K, class V > struct tuple_element < 1, key_val< K, V > > { using type = V; };

}
#line 2 "cp-library/src/utility/vec_op.hpp"
template < class T > key_val< int, T > max_of(const vector< T >& a) {
    int i = std::max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class T > key_val< int, T > min_of(const vector< T >& a) {
    int i = std::min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class S, class T > S sum_of(const vector< T >& a) {
    S sum = 0;
    for(const T x : a) sum += x;
    return sum;
}
template < class S, class T > vector< S > freq_of(const vector< T >& a, T L, T R) {
    vector< S > res(R - L, S(0));
    for(const T x : a) res[x - L] += 1;
    return res;
}
template < class S, class T > struct prefix_sum {
    vector< S > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), S(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    S sum(int L, int R) { return s[R] - s[L]; }
};
#line 3 "cp-library/src/utility/heap.hpp"

template < class T > using heap_min = std::priority_queue< T, std::vector< T >, std::greater< T > >;
template < class T > using heap_max = std::priority_queue< T, std::vector< T >, std::less< T > >;

#line 27 "cp-library/src/cp-template.hpp"

#line 1 "cp-library/src/algorithm/bin_search.hpp"
template < class T, class F >
T bin_search(T ok, T ng, F f) {
    while(abs(ng - ok) > 1) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template < class T, class F >
T bin_search_real(T ok, T ng, F f, int step = 80) {
    while(step--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "cp-library/src/algorithm/argsort.hpp"

template < class T > std::vector< int > argsort(const std::vector< T > &a) {
    std::vector< int > ids((int)a.size());
    std::iota(ids.begin(), ids.end(), 0);
    std::sort(ids.begin(), ids.end(), [&](int i, int j) {
        return a[i] < a[j] || (a[i] == a[j] && i < j);
    });
    return ids;
}
#line 1 "macro.hpp"
namespace macro {

using size_type = int;
template < class container > void  sort(container& a) { std::sort(std:: begin(a), std:: end(a)); }
template < class container > void rsort(container& a) { std::sort(std::rbegin(a), std::rend(a)); }
template < class container > void reverse(container& a) { std::reverse(std::begin(a), std::end(a)); }
template < class container > void unique(container& a) {
    std::sort(std::begin(a), std::end(a));
    a.erase(std::unique(std::begin(a), std::end(a)), std::end(a));
}
template < class container > container  sorted(const container& a) { container b = a;  sort(b); return std::move(b); }
template < class container > container rsorted(const container& a) { container b = a; rsort(b); return std::move(b); }
template < class container, class compare > void sort(container& a, const compare& cmp) { std::sort(std::begin(a), std::end(a), cmp); }
template < class container, class compare > container sorted(const container& a, const compare& cmp) { container b = a; sort(b, cmp); return std::move(b); }
template < class container, class value > size_type lower_bound(const container& a, const value& x) { return std::lower_bound(std::begin(a), std::end(a), x) - std::begin(a); }
template < class container, class value > size_type upper_bound(const container& a, const value& x) { return std::upper_bound(std::begin(a), std::end(a), x) - std::begin(a); }

const std::vector<std::pair<size_type, size_type>> dir4 = { {+1,  0}, {-1,  0}, { 0, +1}, { 0, -1} };
const std::vector<std::pair<size_type, size_type>> dir8 = { {-1, -1}, {-1,  0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1,  0}, {+1, +1} };

#ifdef _DEBUG
#define debug(x) std::cout << "[" << __LINE__ << "] " << #x << ": " << x << std::endl
#else
#define debug(x)
#endif

template < class container > void concat(container& a, const container& b) {
    a.insert(std::end(a), std::begin(b), std::end(b));
}
std::vector<size_type> iota(const size_type n) {
    std::vector<size_type> I(n);
    std::iota(std::begin(I), std::end(I), 0);
    return I;
}
template < class container > std::vector<size_type> sort_idx(const container& a) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return a[i] < a[j] or (a[i] == a[j] and i < j); });
    return I;
}
template < class container, class compare > std::vector<size_type> sort_idx(const container& a, const compare& cmp) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return cmp(a[i], a[j]) or (a[i] == a[j] and i < j); });
    return std::move(I);
}

struct grid {
    using size_type = int;
    size_type H, W;
    grid(const size_type H, const size_type W) : H(H), W(W) {}
    bool contains(const size_type i, const size_type j) {
        return 0 <= i and i < H and 0 <= j and j < W;
    }
};

using f64 = long double;

} // namespace macro

using namespace macro;
#line 1 "cp-library/src/algorithm/ternary_search.hpp"
template < class K, class V, class F >
std::pair< K, V > ternary_search(K L, K R, F f) {
    while(R - L >= K(3)) {
        K kL = (L + L + R) / 3, kR = (L + R + R) / 3;
        V vL = f(kL), vR = f(kR);
        if(vL < vR) R = kR; else L = kL;
    }
    std::pair< K, V > res = {R, f(R)};
    for(K k : rep(L, R)) {
        V v = f(k);
        if(v < res.second) res = std::make_pair(k, v);
    }
    return res;
}

template < class K, class V, class F >
std::pair< K, V > ternary_search_real(K L, K R, F f, int step = 80) {
    while(step--) {
        K kL = (L + L + R) / 3.0, kR = (L + R + R) / 3.0;
        V vL = f(kL), vR = f(kR);
        if(vL < vR) R = kR; else L = kL;
    }
    return std::make_pair(L, f(L));
}
#line 4 "A.cpp"

f64 solve(int N) {
    f64 A = in();
    vector<f64> B(N), C(N), D(N), E(N);
    for(int i : rep(N)) B[i] = in(), C[i] = in(), D[i] = in(), E[i] = in();

    return ternary_search_real<f64, f64>(f64(0), f64(1e6), [&](f64 x) {
        f64 f = A * x;
        for(int i : rep(N)) f += max<f64>(0, E[i] - B[i] * x) / D[i] * C[i];
        return f;
    }, 200).second;
}

int main() {
    while(true) {
        int N = in();
        if(N == 0) return 0;
        printer::precision(20);
        print(solve(N));
    }
}
accuracy: 1
time_ms: 2240
memory_kb: 9664
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef double flt;
const int MAXN = 100000 + 10;
const flt eps = 1e-7;

// Change the arrays to an array of structures
struct Node {
  int vw;
  int pf;
  int vf;
  int th;
} node[MAXN];

int N, pw;

// Function to calculate cost
flt calc(flt W, flt &cost) {
  cost = W * pw;

  // Loop unrolling
  for (int i = 0; i < N; i += 4) {
    for (int j = 0; j < 4 && i + j < N; ++j) {
      flt need = node[i+j].th - W * node[i+j].vw;
      if (need <= 0)
        continue;
      flt f = need / node[i+j].vf;
      cost += f * node[i+j].pf;
    }
  }

  return cost;
}

int main() {
  while (scanf("%d", &N) == 1 && N) {
    scanf("%d", &pw);
    for (int i = 0; i < N; ++i) {
      scanf("%d%d%d%d", &node[i].vw, &node[i].pf, &node[i].vf, &node[i].th);
    }

    flt left = 0, right = INT_MAX;
    flt lastC1, lastC2;
    for (int _ = 0; _ < 200; ++_) {
      flt m1 = (left + left + right) / 3.0;
      flt m2 = (left + right + right) / 3.0;
      flt c1 = calc(m1, lastC1), c2 = calc(m2, lastC2);
      if (c1 < c2)
        right = m2;
      else
        left = m1;
    }

    // Use the stored result of the last calc function call
    printf("%.10f\n", min(lastC1, lastC2));
  }

  return 0;
}
accuracy: 1
time_ms: 760
memory_kb: 5036
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef double flt;
const int MAXN = 100000 + 10;
const flt eps = 1e-7;
int vw[MAXN], pf[MAXN], vf[MAXN], th[MAXN];
int N, pw;

int main() {
  while (scanf("%d", &N) == 1 && N) {
    scanf("%d", &pw);
    for (int i = 0; i < N; ++i) {
      scanf("%d%d%d%d", vw + i, pf + i, vf + i, th + i);
    }
    flt left = 0, right = INT_MAX;
    for (int _ = 0; _ < 200; ++_) {
      flt m1 = (left + left + right) / 3.0;
      flt m2 = (left + right + right) / 3.0;

      // Inlined 'calc' function
      flt cost1 = m1 * pw, cost2 = m2 * pw;
      for (int i = 0; i < N; i += 2) {  // Unrolled loop
        flt need1 = th[i] - m1 * vw[i];
        if (need1 > 0) {
          flt f1 = need1 / vf[i];
          cost1 += f1 * pf[i];
        }
        if (i + 1 < N) {
          flt need2 = th[i + 1] - m1 * vw[i + 1];
          if (need2 > 0) {
            flt f2 = need2 / vf[i + 1];
            cost1 += f2 * pf[i + 1];
          }
        }
        need1 = th[i] - m2 * vw[i];
        if (need1 > 0) {
          flt f1 = need1 / vf[i];
          cost2 += f1 * pf[i];
        }
        if (i + 1 < N) {
          flt need2 = th[i + 1] - m2 * vw[i + 1];
          if (need2 > 0) {
            flt f2 = need2 / vf[i + 1];
            cost2 += f2 * pf[i + 1];
          }
        }
      }

      if (cost1 < cost2)
        right = m2;
      else
        left = m1;
    }
    // Inlined 'calc' function for the final calculation
    flt cost = left * pw;
    for (int i = 0; i < N; ++i) {
      flt need = th[i] - left * vw[i];
      if (need > 0) {
        flt f = need / vf[i];
        cost += f * pf[i];
      }
    }
    printf("%.10f\n", cost);
  }
  return 0;
}
accuracy: 1
time_ms: 560
memory_kb: 4884
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#define MAX 100001
#define inf 1e9
using namespace std;
int n, pw;
vector<double> vw(MAX), pf(MAX), vf(MAX), th(MAX);

double f(double W) {
  double cost = W * pw;
  for (int i = 0; i < n; i++) {
    double W_vw = W * vw[i];
    if (W_vw > th[i])
      continue;
    double sum1 = th[i] - W_vw;
    double sum2 = sum1 / vf[i];
    cost += sum2 * pf[i];
  }
  return cost;
}

int main() {
  while (1) {
    cin >> n >> pw;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> vw[i] >> pf[i] >> vf[i] >> th[i];
    double l = 0, r = inf;
    for (int i = 0; i < 200; i++) {
      double m1 = (l * 2.0 + r) / 3.0;
      double m2 = (l + r * 2.0) / 3.0;
      double res1 = f(m1);
      double res2 = f(m2);
      if (res1 < res2)
        r = m2;
      else
        l = m1;
    }
    printf("%.4f\n", f(l));
  }
  return 0;
}
accuracy: 1
time_ms: 1890
memory_kb: 5776
final_rank: 15

code_snippet: #include <bits/stdc++.h>
#define MAX 100001
#define inf 1e9
using namespace std;

int n, pw;
double vw[MAX], pf[MAX], vf[MAX], th[MAX];

double f(double W) {
  double cost = W * pw;
  #pragma omp simd
  for (int i = 0; i < n; i++) {
    double Wvw = W * vw[i];
    if (Wvw > th[i])
      continue;
    double sum1 = th[i] - Wvw;
    double sum2 = sum1 / vf[i];
    cost += sum2 * pf[i];
  }
  return cost;
}

int main() {
  while (1) {
    cin >> n >> pw;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> vw[i] >> pf[i] >> vf[i] >> th[i];
    double l = 0, r = inf;
    for (int i = 0; i < 200; i++) {
      double m1 = (l * 2.0 + r) / 3.0;
      double m2 = (l + r * 2.0) / 3.0;
      double res1 = f(m1);
      double res2 = f(m2);
      if (res1 < res2)
        r = m2;
      else
        l = m1;
    }
    printf("%.4f\n", f(l));
  }
  return 0;
}
accuracy: 1
time_ms: 1880
memory_kb: 6192
final_rank: 16

code_snippet: #include <bits/stdc++.h>
const int MAX = 100001;
const double inf = 1e9;
using namespace std;

int n, pw;
vector<double> vw(MAX), pf(MAX), vf(MAX), th(MAX);

double f(double W) {
  double cost = W * pw;
  for (int i = 0; i < n; i++) {
    double W_vw = W * vw[i];
    if (W_vw > th[i])
      continue;
    double sum1 = th[i] - W_vw;
    double sum2 = sum1 / vf[i];
    cost += sum2 * pf[i];
  }
  return cost;
}

int main() {
  while (1) {
    cin >> n >> pw;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> vw[i] >> pf[i] >> vf[i] >> th[i];
    double l = 0, r = inf;
    for (int i = 0; i < 200; i++) {
      double m1 = (l * 2.0 + r) / 3.0;
      double m2 = (l + r * 2.0) / 3.0;
      double res1 = f(m1);
      double res2 = f(m2);
      if (res1 < res2)
        r = m2;
      else
        l = m1;
    }
    cout << fixed << setprecision(4) << f(l) << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 1890
memory_kb: 5736
final_rank: 14

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define inf 1e9
using namespace std;
int n, pw;
vector<double> vw, pf, vf, th;
double f(double W) {
  double cost = W * pw;
  for (int i = 0; i < n; i++) {
    double weight = W * vw[i];
    if (weight > th[i])
      continue;
    double sum1 = th[i] - weight;
    double sum2 = sum1 / vf[i];
    cost += sum2 * pf[i];
  }
  return cost;
}
int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  while (1) {
    cin >> n >> pw;
    if (n == 0)
      break;
    vw.resize(n); pf.resize(n); vf.resize(n); th.resize(n);
    for (int i = 0; i < n; i++)
      cin >> vw[i] >> pf[i] >> vf[i] >> th[i];
    double l = 0, r = inf;
    for (int i = 0; i < 200; i++) {
      double m1 = (l * 2.0 + r) / 3.0;
      double m2 = (l + r * 2.0) / 3.0;
      double res1 = f(m1);
      double res2 = f(m2);
      if (res1 < res2)
        r = m2;
      else
        l = m1;
    }
    printf("%.4f\n", f(l));
  }
  return 0;
}
accuracy: 1
time_ms: 1300
memory_kb: 6260
final_rank: 10

code_snippet: #include <bits/stdc++.h>
#define MAX 100001
#define inf 1e9
using namespace std;
int n, pw;
double vw[MAX], pf[MAX], vf[MAX], th[MAX];

double f(double W) {
  double cost = W * pw;
  for (int i = 0; i < n; i++) {
    double Wvw = W * vw[i]; // Store the result of W * vw[i] in a variable
    if (Wvw > th[i])
      continue;
    double sum1 = th[i] - Wvw; // Use the stored result
    double sum2 = sum1 / vf[i];
    cost += sum2 * pf[i];
  }
  return cost;
}

int main() {
  while (1) {
    scanf("%d %d", &n, &pw); // Replace cin with scanf
    if (n == 0)
      break;
    for (int i = 0; i < n; i++)
      scanf("%lf %lf %lf %lf", &vw[i], &pf[i], &vf[i], &th[i]); // Replace cin with scanf
    double l = 0, r = inf;
    double resl = f(l), res1, res2; // Store the result of f(l) in a variable
    for (int i = 0; i < 200; i++) {
      double m1 = (l * 2.0 + r) / 3.0;
      double m2 = (l + r * 2.0) / 3.0;
      res1 = f(m1);
      res2 = f(m2);
      if (res1 < res2)
        r = m2;
      else
        l = m1;
      resl = res1; // Update the stored result
    }
    printf("%.4f\n", resl); // Use the stored result
  }
  return 0;
}
accuracy: 1
time_ms: 1000
memory_kb: 6256
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef double flt;
const int MAXN = 100000 + 10;
const flt eps = 1e-7;
vector<int> vw, pf, vf, th;
int N, pw;

flt calc(flt W) {
  flt cost = W * pw;
  flt need;
  for (int i = 0; i < N; ++i) {
    need = th[i] - W * vw[i];
    if (need <= 0)
      continue;
    flt f = need / vf[i];
    cost += f * pf[i];
  }
  return cost;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  while (scanf("%d", &N) == 1 && N) {
    scanf("%d", &pw);
    vw.resize(N);
    pf.resize(N);
    vf.resize(N);
    th.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%d%d%d%d", &vw[i], &pf[i], &vf[i], &th[i]);
    }
    flt left = 0, right = INT_MAX;
    for (int _ = 0; _ < 200; ++_) {
      flt m1 = (left + left + right) / 3.0;
      flt m2 = (left + right + right) / 3.0;
      flt c1 = calc(m1), c2 = calc(m2);
      if (c1 < c2)
        right = m2;
      else
        left = m1;
    }
    printf("%.10f\n", calc(left));
  }
  return 0;
}
accuracy: 1
time_ms: 670
memory_kb: 4748
final_rank: 3

code_snippet: #include <bits/stdc++.h>
#define MAX 100001
#define inf 1e9
using namespace std;

int n, pw;
vector<double> vw(MAX), pf(MAX), vf(MAX), th(MAX);

double f(double W) {
  double cost = W * pw;
  double vw_i, th_i, sum1, sum2;
  for (int i = 0; i < n; i++) {
    vw_i = vw[i];
    th_i = th[i];
    if (W * vw_i > th_i)
      continue;
    sum1 = th_i - W * vw_i;
    sum2 = sum1 / vf[i];
    cost += sum2 * pf[i];
  }
  return cost;
}

int main() {
  while (1) {
    cin >> n >> pw;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> vw[i] >> pf[i] >> vf[i] >> th[i];
    double l = 0, r = inf;
    for (int i = 0; i < 200; i += 2) {
      double m1 = (l * 2.0 + r) / 3.0;
      double m2 = (l + r * 2.0) / 3.0;
      double res1 = f(m1);
      double res2 = f(m2);
      if (res1 < res2)
        r = m2;
      else
        l = m1;
      m1 = (l * 2.0 + r) / 3.0;
      m2 = (l + r * 2.0) / 3.0;
      res1 = f(m1);
      res2 = f(m2);
      if (res1 < res2)
        r = m2;
      else
        l = m1;
    }
    printf("%.4f\n", f(l));
  }
  return 0;
}
accuracy: 1
time_ms: 1890
memory_kb: 5728
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef double flt;
const int MAXN = 100000 + 10;
const flt eps = 1e-7;
int vw[MAXN], pf[MAXN], vf[MAXN], th[MAXN];
int N, pw;

flt calc(flt W) {
  flt cost = W * pw;
  for (int i = 0; i < N; ++i) {
    flt need = th[i] - W * vw[i];
    if (need > 0) {
      flt f = need / vf[i];
      cost += f * pf[i];
    }
  }
  return cost;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  while (scanf("%d", &N) == 1 && N) {
    scanf("%d", &pw);
    for (int i = 0; i < N; ++i) {
      scanf("%d%d%d%d", vw + i, pf + i, vf + i, th + i);
    }
    flt left = 0, right = INT_MAX;
    for (int _ = 0; _ < 200; ++_) {
      flt m1 = (left + left + right) / 3.0;
      flt m2 = (left + right + right) / 3.0;
      flt c1 = calc(m1), c2 = calc(m2);
      if (c1 < c2)
        right = m2;
      else
        left = m1;
    }
    printf("%.10f\n", calc(left));
  }
  return 0;
}
accuracy: 1
time_ms: 660
memory_kb: 5112
final_rank: 4

code_snippet: #include <cstdio>
#include <climits>
#define MAXN 100000 + 10
const double eps = 1e-7;
int vw[MAXN], pf[MAXN], vf[MAXN], th[MAXN];
int N, pw;

double calc(double W) {
  double cost = W * pw;
  double W_vw[MAXN];
  for (int i = 0; i < N; ++i) {
    W_vw[i] = W * vw[i];
  }
  for (int i = 0; i < N; ++i) {
    double need = th[i] - W_vw[i];
    if (need > 0) {
      double f = need / vf[i];
      cost += f * pf[i];
    }
  }
  return cost;
}

int main() {
  while (scanf("%d", &N) == 1 && N) {
    scanf("%d", &pw);
    for (int i = 0; i < N; ++i) {
      scanf("%d%d%d%d", vw + i, pf + i, vf + i, th + i);
    }
    double left = 0, right = INT_MAX;
    for (int _ = 0; _ < 200; ++_) {
      double m1 = (left + left + right) / 3.0;
      double m2 = (left + right + right) / 3.0;
      double c1 = calc(m1), c2 = calc(m2);
      if (c1 < c2)
        right = m2;
      else
        left = m1;
    }
    printf("%.10f\n", calc(left));
  }
  return 0;
}
accuracy: 1
time_ms: 1030
memory_kb: 5280
final_rank: 6

code_snippet: #include <bits/stdc++.h>
#define MAX 100001
#define inf 1e9
using namespace std;
int n, pw;
double vw[MAX], pf[MAX], vf[MAX], th[MAX];
double f(double W) {
  double cost = W * pw;
  for (int i = 0; i < n; i++) {
    if (W * vw[i] > th[i])
      continue;
    double sum1 = th[i] - W * vw[i];
    double sum2 = sum1 * (1.0 / vf[i]);
    cost += sum2 * pf[i];
  }
  return cost;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  double m1, m2, res1, res2; // Reduce the scope of variables
  while (1) {
    scanf("%d %d", &n, &pw);
    if (n == 0)
      break;
    for (int i = 0; i < n; i++)
      scanf("%lf %lf %lf %lf", &vw[i], &pf[i], &vf[i], &th[i]);
    double l = 0, r = inf;
    for (int i = 0; i < 200; i++) {
      m1 = (l * 2.0 + r) / 3.0;
      m2 = (l + r * 2.0) / 3.0;
      res1 = f(m1);
      res2 = f(m2);
      if (res1 < res2)
        r = m2;
      else
        l = m1;
    }
    printf("%.4f\n", f(l));
  }
  return 0;
}
accuracy: 1
time_ms: 980
memory_kb: 6284
final_rank: 7

code_snippet: #include <bits/stdc++.h>
#define MAX 100001
#define inf 1e9
using namespace std;
int n, pw;
double vw[MAX], pf[MAX], vf[MAX], th[MAX];
double f(double W) {
  double cost = W * pw;
  for (int i = 0; i < n; ++i) {
    double W_vw = W * vw[i];
    if (W_vw > th[i])
      continue;
    double sum1 = th[i] - W_vw;
    double sum2 = sum1 / vf[i];
    cost += sum2 * pf[i];
  }
  return cost;
}
int main() {
  while (1) {
    cin >> n >> pw;
    if (n == 0)
      break;
    for (int i = 0; i < n; ++i)
      cin >> vw[i] >> pf[i] >> vf[i] >> th[i];
    double l = 0, r = inf;
    for (int i = 0; i < 200; ++i) {
      double m1 = (l * 2.0 + r) / 3.0;
      double m2 = (l + r * 2.0) / 3.0;
      double res1 = f(m1);
      double res2 = f(m2);
      if (res1 < res2)
        r = m2;
      else
        l = m1;
    }
    printf("%.4f\n", f(l));
  }
  return 0;
}
accuracy: 1
time_ms: 1890
memory_kb: 6232
final_rank: 18

code_snippet: #include <iostream>
#include <cstdio>

#define MAX 100001
#define inf 1e9

double vw[MAX], pf[MAX], vf[MAX], th[MAX];

double f(double W, int n, int pw) {
  double cost = W * pw;
  for (int i = 0; i < n; i++) {
    double temp = W * vw[i];
    if (temp > th[i])
      continue;
    double sum1 = th[i] - temp;
    double sum2 = sum1 / vf[i];
    cost += sum2 * pf[i];
  }
  return cost;
}

int main() {
  int n, pw;
  while (1) {
    std::cin >> n >> pw;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++)
      std::cin >> vw[i] >> pf[i] >> vf[i] >> th[i];
    double l = 0, r = inf;
    for (int i = 0; i < 200; i++) {
      double m1 = (l * 2.0 + r) / 3.0;
      double m2 = (l + r * 2.0) / 3.0;
      double res1 = f(m1, n, pw);
      double res2 = f(m2, n, pw);
      if (res1 < res2)
        r = m2;
      else
        l = m1;
    }
    printf("%.4f\n", f(l, n, pw));
  }
  return 0;
}
accuracy: 1
time_ms: 1880
memory_kb: 6256
final_rank: 17