Problem:
Problem F:
Water Tank
You built an apartment. The apartment has a water tank with a capacity of
L
in order to
store water for the residents. The tank works as a buffer between the water company and the
residents.
It is required to keep the tank "not empty" at least during use of water. A pump is used to
provide water into the tank. From the viewpoint of avoiding water shortage, a more powerful
pump is better, of course. But such powerful pumps are expensive. That’s the life.
You have a daily schedule table of water usage. It does not differ over days. The table is
composed of some schedules. Each schedule is indicated by the starting time of usage, the
ending time and the used volume per unit of time during the given time span.
All right, you can find the minimum required speed of providing water for days from the schedule
table. You are to write a program to compute it.
You can assume the following conditions.
A day consists of 86,400 units of time.
No schedule starts before the time 0 (the beginning of the day).
No schedule ends after the time 86,400 (the end of the day).
No two schedules overlap.
Water is not consumed without schedules.
The tank is full of water when the tank starts its work.
Input
The input is a sequence of datasets. Each dataset corresponds to a schedule table in the following
format:
N L
s
1
t
1
u
1
...
s
N
t
N
u
N
The first line of a dataset contains two integers
N
and
L
(1 ≤
N
≤ 86400, 1 ≤
L
≤ 10
6
), which
represents the number of schedule in the table and the capacity of the tank, respectively.
The following
N
lines describe the
N
schedules. The (
i
+ 1)-th line of the dataset corresponds to the
i
-th schedule, which consists of three integers
s
i
,
t
i
and
u
i
. The first two integers
s
i
and
t
i
indicate the starting time and the ending time of the schedule. The last integer
u
i
(1 ≤
u
i
≤ 10
6
) indicates the consumed volume per unit of time during the schedule. It is
guaranteed that 0 ≤
s
1
<
t
1
≤
s
2
<
t
2
≤ ... ≤
s
n
<
t
n
≤ 86400.
The input is terminated by a line with two zeros. This line should not be processed.
Output
For each case, print the minimum required amount of water per unit of time provided by the
pump in a line. The amount may be printed with an arbitrary number of digits after the decimal
point, but should not contain an absolute error greater than 10
-6
.
Sample Input
1 100
0 86400 1
1 100
43200 86400 1
0 0
Output for the Sample Input
1.000000
0.997685

Submitted solutions:

code_snippet: #include<iostream>
#include<stdio.h>
#include<cstring>

using namespace std;

long long n,l,s[100000],t[100000],u[100000],i,j;
double ans,lb,ub,mid;

bool tr ( double t_flow ) {

	double cap=l;
	for(i=0;i<=n+1;i++)
	{
		cap=cap+t_flow*(s[i]-t[i-1]); if(cap>l) cap=l;
		cap=cap-(t[i]-s[i])*(u[i]-t_flow); if(cap>l) cap=l;
		if(cap<1e-10) return false;
	}

	if(cap>=l) return true;
	double a=cap;
	for(i=0;i<=n+1;i++)
	{
		cap=cap+t_flow*(s[i]-t[i-1]); if(cap>l) cap=l;
		cap=cap-(t[i]-s[i])*(u[i]-t_flow); if(cap>l) cap=l;
		if(cap<1e-10) return false;
	}
//	printf("%.7lf\n",cap);

	return a-cap<1e-10;
}

int main() {

	while(scanf("%lld %lld",&n,&l)!=EOF)
	{
		if(n==0&&l==0) break; ub=0;
		for(i=1;i<=n;i++)
		{
			scanf("%lld %lld %lld",&s[i],&t[i],&u[i]);
			if(u[i]>ub) ub=u[i];
		}
		s[0]=0; t[0]=s[1]; u[0]=0;
		s[n+1]=t[n]; t[n+1]=86400; u[n+1]=0;
		lb=0; ans=ub;
		while(lb<ub+1e-10)
		{
			if(ub-lb<1e-8) break;

			mid=(lb+ub)/2;
//			printf("%.7lf %.7lf %.7lf\n",lb,mid,ub);
			if(tr(mid))
			{
				if(ans>mid) ans=mid;
				ub=mid;
			}
			else lb=mid;
		}

		printf("%.7lf\n",ans);

	}

	return 0;

}
accuracy: 1
time_ms: 60
memory_kb: 5516
final_rank: 9

code_snippet: #line 1 "A.cpp"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define srep(i, s, t) for(int i = (s); i < (t); i++)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
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; }
using i64 = long long;
using f64 = long double;
i64 floor_div(const i64 n, const i64 d) { assert(d != 0); return n / d - static_cast<i64>((n ^ d) <  0 && n % d != 0); }
i64  ceil_div(const i64 n, const i64 d) { assert(d != 0); return n / d + static_cast<i64>((n ^ d) >= 0 && n % d != 0); }

f64 solve(int N, int L) {
    vector<tuple<int, int, int>> a(N);
    for(auto &[s, t, u] : a) cin >> s >> t >> u;

    auto F = [&](f64 x) -> bool {
        f64 now = L;
        int p = 0;
        for(auto [s, t, u] : a) {
            now += (s - p) * (x);
            now = clamp<f64>(now, 0, L);
            now += (t - s) * (x - u);
            if(now < 0) return false;
            now = clamp<f64>(now, 0, L);
            p = t;
        }
        const f64 L1 = now;
        for(auto [s, t, u] : a) {
            s += 86400;
            t += 86400;
            now += (s - p) * (x);
            now = clamp<f64>(now, 0, L);
            now += (t - s) * (x - u);
            if(now < 0) return false;
            now = clamp<f64>(now, 0, L);
            p = t;
        }
        const f64 L2 = now;
        return L1 - 1e-6 <= L2;
    };

    f64 ok = 1e7, ng = 0.0;
    rep(_, 100) {
        f64 mid = (ok + ng) / 2.0;
        (F(mid) ? ok : ng) = mid;
    }
    return ok;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    
    while(true) {
        int N, L; cin >> N >> L;
        if(make_pair(N, L) == make_pair(0, 0)) return 0;
        cout << fixed << setprecision(20) << solve(N, L) << "\n";
    }
}
accuracy: 1
time_ms: 210
memory_kb: 4520
final_rank: 7

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
 */

double Simulation(vector<double> A, double L, double S) {
    double Cur = S;
    rep(i,0,86400) {
        Cur -= A[i];
        chmin(Cur,L);
        if (Cur <= 0.0) return -1.0;
    }
    return Cur;
}

bool Solve(vector<double> A, double L, double M) {
    rep(i,0,86400) A[i] -= M;
    double L1 = Simulation(A,L,L);
    if (L1 < 0.0) return false;
    double L2 = Simulation(A,L,L1);
    if (L2 < L1) return false;
    return true;
}

int main() {
while(1) {
    int N;
    double L;
    cin >> N >> L;
    if (N == 0) return 0;
    vector<double> A(86400,0.0);
    rep(i,0,N) {
        int S, T;
        double D;
        cin >> S >> T >> D;
        rep(j,S,T) A[j] = D;
    }
    double NG = 0.0, OK = 1000000.0;
    while(OK-NG>1e-7) {
        double MID = (OK+NG)/2.0;
        if (Solve(A,L,MID)) OK = MID;
        else NG = MID;
    }
    printf("%.12f\n",(OK+NG)/2.0);
}
}
accuracy: 1
time_ms: 2430
memory_kb: 5232
final_rank: 14

code_snippet: //
// Created by akey2 on 2023/11/23.
//

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define ov(a, b, c, name, ...) name
#define rep2(i, a, b) for(ll i = a; i < b;i++)
#define rep1(i, n) rep2(i, 0, n)
#define rep0(n) rep1(ieiurieui, n)
#define rep(...) ov(__VA_ARGS__, rep2, rep1, rep0)(__VA_ARGS__)
#define all(a) begin(a), end(a)
#define si(a) (int)(a.size())
#define fore(e, v) for(auto &&e : v)
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define eb emplace_back

struct IO {
    IO() {
        ios_base::sync_with_stdio(0);
        cin.tie(0), cout.tie(0);
        cout << setprecision(11) << fixed;
    }
} io;

int main() {
    while (true) {
        int n, L;
        cin >> n >> L;
        vi s(n), t(n), u(n);
        rep(i, n) cin >> s[i] >> t[i] >> u[i];
        if (!n and !L) {
            exit(0);
        }

        double ok = 1e9, ng = 0;
        rep(60) {
            double mid = (ok + ng) / 2;
            double now = L;
            int T = 0;
            bool flag = true;
            rep(i, n) {
                now = min<double>(L, now + (s[i] - T) * mid);
                now = min<double>(L, now + (mid - u[i]) * (t[i] - s[i]));
                T = t[i];
                if (now < 0) flag = false;
            }
            now += mid * (86400 - T);
            if(now >= L) now = L;
            double s2 = now;
            bool flag2 = false;
            T = 0;
            rep(i, n) {
                now += (s[i] - T) * mid;
                if(now >= L) flag2 = true;
                now = min<double>(now, L);
                if(now < 0) flag = false;
                now += (mid - u[i]) * (t[i] - s[i]);
                if(now >= L) flag2 = true, now = L;
                if(now < 0) flag = false;
//                cout << now << " " << flag << endl;
                T = t[i];
            }
            now += mid * (86400 - T);
            if(now >= L) flag2 = true, now = L;

            (flag and flag2 ? ok : ng) = mid;
        }
        cout << ok << endl;
    }
}
accuracy: 1
time_ms: 110
memory_kb: 4140
final_rank: 3

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

typedef string::const_iterator State;
#define eps 1e-8L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
#define REP(a, b) for (long long(a) = 0; (a) < (b); ++(a))
#define ALL(x) (x).begin(), (x).end()

#define int long long

void solve()
{
  int n;
  cin >> n;
  if (n == 0)
    exit(0);
  ld l;
  cin >> l;
  vector<tuple<int, int, ld>> inputs;
  REP(i, n)
  {
    int a, b, c;
    cin >> a >> b >> c;
    inputs.push_back({a, b, c});
  }
  inputs.push_back({0, 0, 0});
  inputs.push_back({86400, 86400, 0});
  sort(ALL(inputs));
  ld bot = 1e9;
  ld top = 0;
  REP(t, 200)
  {
    ld mid = (bot + top) / 2.0L;

    ld now = l;
    int ok = 1;
    ld tmp = -1;
    REP(t, 2)
    {
      for (int i = 1; i < inputs.size(); ++i)
      {
        now += (ld)(get<0>(inputs[i]) - get<1>(inputs[i - 1])) * mid;
        now = min(now, l);
        now += (ld)(get<1>(inputs[i]) - get<0>(inputs[i])) * (mid - get<2>(inputs[i]));
        now = min(now, l);
        if (now < -eps)
        {
          ok = 0;
        }
      }
      if (t == 0)
      {
        tmp = now;
      }
      else
      {
        if (abs(tmp - now) > eps)
        {
          ok = 0;
        }
      }
    }
    if (ok)
    {
      bot = mid;
    }
    else
    {
      top = mid;
    }
  }
  cout << bot << endl;
}

#undef int

// generated by oj-template v4.7.2
// (https://github.com/online-judge-tools/template-generator)
int main()
{
  // Fasterize input/output script
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(100);
  // scanf/printf user should delete this fasterize input/output script

  int t = 1000;
  // cin >> t; // comment out if solving multi testcase
  for (int testCase = 1; testCase <= t; ++testCase)
  {
    solve();
  }
  return 0;
}
accuracy: 1
time_ms: 480
memory_kb: 9992
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    const int day = 86400;

    while (1) {
        int N, L;
        cin >> N >> L;
        if (N == 0) break;
        double lb = 0, ub = 1e9;
        vector<int> s(N), t(N), u(N);
        rep(i,0,N) cin >> s[i] >> t[i] >> u[i];
        s.push_back(day);
        t.push_back(day);
        u.push_back(0);
        rep(_,0,100) {
            double m = (lb + ub) / 2;
            double min_start = L;
            double min_mid = L;
            double h = L, time = 0;
            rep(i,0,N+1) {
                h += (s[i] - time) * m;
                if (h > L) {
                    double sub = min(h - L, min_mid);
                    min_start -= sub;
                    min_mid -= sub;
                    h = L;
                }
                h += (t[i] - s[i]) * (m - u[i]);
                if (h < 0) {
                    min_start = 1e9;
                    break;
                }
                if (h > L) {
                    double sub = min(h - L, min_mid);
                    min_start -= sub;
                    min_mid -= sub;
                    h = L;
                } else {
                    min_mid = min(min_mid, h);
                }
                time = t[i];
            }
            if (min_start <= h) {
                ub = m;
            } else {
                lb = m;
            }
        }
        cout << lb << "\n";
    }
}
accuracy: 1
time_ms: 80
memory_kb: 4912
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>
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;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,u;
    while(cin >> n >> u,n){
        vector<pair<pair<int,int>,int>> v(n);
        for(int i=0;i<n;i++){
            cin >> v[i].first.first >> v[i].first.second >> v[i].second;
        }
        sort(v.begin(), v.end());
        double mx = u;
        auto check = [&](double mid)->bool{
            double tmp;
            {
                double cur = mx;
                int day = 0;
                for(int i=0;i<n;i++){
                    cur = min(mx,cur+mid*(v[i].first.first-day));
                    cur -= (v[i].second-mid) * (v[i].first.second-v[i].first.first);
                    if(cur < 0) return false;
                    cur = min(cur, mx);
                    day = v[i].first.second;
                }
                cur = min(mx,cur+mid*(86400-day));
                tmp = cur;
            }
            double tmp2;
            {
                double cur = tmp;
                int day = 0;
                for(int i=0;i<n;i++){
                    cur = min(mx,cur+mid*(v[i].first.first-day));
                    cur -= (v[i].second-mid) * (v[i].first.second-v[i].first.first);
                    if(cur < 0) return false;
                    cur = min(cur, mx);
                    day = v[i].first.second;
                }
                cur = min(mx,cur+mid*(86400-day));
                tmp2 = cur;
            }
            return (tmp-1e-7<tmp2);
        };
        double L = 0.0, R = 1e6;
        for(int i=0;i<100;i++){
            double mid = (L+R)/2;
            if(check(mid)){
                R = mid;
            }
            else{
                L = mid;
            }
        }
        printf("%.9f\n",R);
    }
}
accuracy: 1
time_ms: 120
memory_kb: 4340
final_rank: 5

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

void solve(int N, int L) {
    vector<int> s(N), t(N), u(N);
    for (int i = 0; i < N; i++) cin >> s[i] >> t[i] >> u[i];

    for (int i = 0; i < N; i++) {
        s.emplace_back(s[i] + 86400);
        t.emplace_back(t[i] + 86400);
        u.emplace_back(u[i]);
    }
    auto check = [&](double x) {
        double cur = L, half;
        for (int i = 0, pre = 0; i < 2 * N; pre = t[i++]) {
            cur = min(double(L), cur + x * (s[i] - pre));
            cur = min(double(L), cur + (x - u[i]) * (t[i] - s[i]));
            if (cur < 0) return false;
            if (i + 1 == N) half = cur;
        }
        return half <= cur;
    };

    double lb = 0, ub = 1e6;
    for (int _ = 0; _ < 100; _++) {
        double mid = (ub + lb) / 2;
        (check(mid) ? ub : lb) = mid;
    }

    cout << ub << '\n';
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int N, L;
    while (cin >> N >> L, N) solve(N, L);
    return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 5476
final_rank: 11

code_snippet: #define LOCAL
#include <bits/stdc++.h>
using namespace std;
#pragma region Macros
typedef long long ll;
typedef __int128_t i128;
typedef unsigned int uint;
typedef unsigned long long ull;
#define ALL(x) (x).begin(), (x).end()

template <typename T> istream& operator>>(istream& is, vector<T>& v) {
    for (T& x : v) is >> x;
    return is;
}
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    for (int i = 0; i < (int)v.size(); i++) {
        os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
    }
    return os;
}
template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <typename T, typename U> ostream& operator<<(ostream& os, const map<T, U>& m) {
    os << '{';
    for (auto itr = m.begin(); itr != m.end();) {
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr != m.end()) os << ',';
    }
    os << '}';
    return os;
}
template <typename T, typename U> ostream& operator<<(ostream& os, const unordered_map<T, U>& m) {
    os << '{';
    for (auto itr = m.begin(); itr != m.end();) {
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr != m.end()) os << ',';
    }
    os << '}';
    return os;
}
template <typename T> ostream& operator<<(ostream& os, const set<T>& s) {
    os << '{';
    for (auto itr = s.begin(); itr != s.end();) {
        os << *itr;
        if (++itr != s.end()) os << ',';
    }
    os << '}';
    return os;
}
template <typename T> ostream& operator<<(ostream& os, const multiset<T>& s) {
    os << '{';
    for (auto itr = s.begin(); itr != s.end();) {
        os << *itr;
        if (++itr != s.end()) os << ',';
    }
    os << '}';
    return os;
}
template <typename T> ostream& operator<<(ostream& os, const unordered_set<T>& s) {
    os << '{';
    for (auto itr = s.begin(); itr != s.end();) {
        os << *itr;
        if (++itr != s.end()) os << ',';
    }
    os << '}';
    return os;
}
template <typename T> ostream& operator<<(ostream& os, const deque<T>& v) {
    for (int i = 0; i < (int)v.size(); i++) {
        os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
    }
    return os;
}

template <int i, typename T> void print_tuple(ostream&, const T&) {}
template <int i, typename T, typename H, class... Args> void print_tuple(ostream& os, const T& t) {
    if (i) os << ',';
    os << get<i>(t);
    print_tuple<i + 1, T, Args...>(os, t);
}
template <typename... Args> ostream& operator<<(ostream& os, const tuple<Args...>& t) {
    os << '{';
    print_tuple<0, tuple<Args...>, Args...>(os, t);
    return os << '}';
}

void debug_out() { cerr << '\n'; }
template <class Head, class... Tail> void debug_out(Head&& head, Tail&&... tail) {
    cerr << head;
    if (sizeof...(Tail) > 0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...)                                                                   \
    cerr << " ";                                                                     \
    cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n'; \
    cerr << " ";                                                                     \
    debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template <typename T> T gcd(T x, T y) { return y != 0 ? gcd(y, x % y) : x; }
template <typename T> T lcm(T x, T y) { return x / gcd(x, y) * y; }

int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }
int topbit(long long t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }
int botbit(signed a) { return a == 0 ? 32 : __builtin_ctz(a); }
int botbit(long long a) { return a == 0 ? 64 : __builtin_ctzll(a); }
int popcount(signed t) { return __builtin_popcount(t); }
int popcount(long long t) { return __builtin_popcountll(t); }
bool ispow2(int i) { return i && (i & -i) == i; }

template <class T> T ceil(T x, T y) {
    assert(y >= 1);
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <class T> T floor(T x, T y) {
    assert(y >= 1);
    return (x > 0 ? x / y : (x - y + 1) / y);
}

template <class T1, class T2> inline bool chmin(T1& a, T2 b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T1, class T2> inline bool chmax(T1& a, T2 b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

const int INF = 1e9;
const long long IINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const char dir[4] = {'D', 'R', 'U', 'L'};
const long long MOD = 1000000007;
// const long long MOD = 998244353;

void solve(int N, int L) {
    vector<int> s(N), t(N), u(N);
    for (int i = 0; i < N; i++) cin >> s[i] >> t[i] >> u[i];

    for (int i = 0; i < N; i++) {
        s.emplace_back(s[i] + 86400);
        t.emplace_back(t[i] + 86400);
        u.emplace_back(u[i]);
    }
    auto check = [&](double x) {
        double cur = L, half;
        for (int i = 0, pre = 0; i < 2 * N; pre = t[i++]) {
            cur = min(double(L), cur + x * (s[i] - pre));
            cur = min(double(L), cur + (x - u[i]) * (t[i] - s[i]));
            if (cur < 0) return false;
            if (i + 1 == N) half = cur;
        }
        return half <= cur;
    };

    double lb = 0, ub = 1e6;
    for (int _ = 0; _ < 100; _++) {
        double mid = (ub + lb) / 2;
        (check(mid) ? ub : lb) = mid;
    }

    cout << ub << '\n';
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int N, L;
    while (cin >> N >> L, N) solve(N, L);
    return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 5460
final_rank: 10

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#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()
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-8;
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);}
//const int mod = 1e9 + 7;
const int mod = 998244353;

int main(){
    while(1){
        int n,L; cin >> n >> L;
        if(n+L==0) break;
        vl s(n),t(n),u(n);
        rep(i,n) cin >> s[i] >> t[i] >> u[i];
        n++;
        s.push_back(86400); t.push_back(86400); u.push_back(0);
        auto f = [&](double x) -> bool {
            double ok = L + 1, ng = 0;
            rep(z,50){
                double mid = (ok+ng) / 2.0;
                double wat = mid;
                double T = 0;
                bool f = true;
                rep(i,n){
                    wat = min((double)L, wat + x*(s[i]-T));
                    wat = min((double)L, wat + (x-u[i])*(t[i]-s[i]));
                    T = t[i];
                    if(wat < -eps) f = false;
                }
                if(f) ok = mid;
                else ng = mid;
            }
            if(ok > L + eps) return false;
            double l = -1, r = (double)L + eps;
            rep(z,50){
                double m = (l+r) / 2.0;
                double wat = m;
                double T = 0;
                rep(i,n){
                    wat = min((double)L, wat + x*(s[i]-T));
                    wat = min((double)L, wat + (x-u[i])*(t[i]-s[i]));
                    T = t[i];
                }
                if(wat < m - eps) r = m;
                else l = m;
            }
            return ok <= l + eps;
        };
        double ok = 1e6 + 5, ng = 0.0;
        rep(z,50){
            double mid = (ok+ng) / 2.0;
            if(f(mid)) ok = mid;
            else ng = mid;
        }
        printf("%.10f\n",ok);
    }
}
accuracy: 1
time_ms: 7200
memory_kb: 6512
final_rank: 20

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#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()
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-8;
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);}
//const int mod = 1e9 + 7;
const int mod = 998244353;

int main(){
    while(1){
        int n,L; cin >> n >> L;
        if(n+L==0) break;
        vl s(n),t(n),u(n);
        rep(i,n) cin >> s[i] >> t[i] >> u[i];
        n++;
        s.push_back(86400); t.push_back(86400); u.push_back(0);
        auto f = [&](double x) -> bool {
            double ok = L + 1, ng = 0;
            rep(z,40){
                double mid = (ok+ng) / 2.0;
                double wat = mid;
                double T = 0;
                bool f = true;
                rep(i,n){
                    wat = min((double)L, wat + x*(s[i]-T));
                    wat = min((double)L, wat + (x-u[i])*(t[i]-s[i]));
                    T = t[i];
                    if(wat < -eps) f = false;
                }
                if(f) ok = mid;
                else ng = mid;
            }
            if(ok > L + eps) return false;
            double l = -1, r = (double)L + eps;
            rep(z,40){
                double m = (l+r) / 2.0;
                double wat = m;
                double T = 0;
                rep(i,n){
                    wat = min((double)L, wat + x*(s[i]-T));
                    wat = min((double)L, wat + (x-u[i])*(t[i]-s[i]));
                    T = t[i];
                }
                if(wat < m - eps) r = m;
                else l = m;
            }
            return ok <= l + eps;
        };
        double ok = 1e6 + 5, ng = 0.0;
        rep(z,40){
            double mid = (ok+ng) / 2.0;
            if(f(mid)) ok = mid;
            else ng = mid;
        }
        printf("%.10f\n",ok);
    }
}
accuracy: 1
time_ms: 4660
memory_kb: 6400
final_rank: 17

code_snippet: #include <iostream>
#include <iomanip>
#include <vector>

using namespace std;
using ldouble = long double;

bool solve() {
    int n;
    ldouble xmax;
    cin >> n >> xmax;
    if (n == 0) return false;

    vector<pair<ldouble, ldouble>> events;
    while (n--) {
        ldouble s, t, u;
        cin >> s >> t >> u;
        events.emplace_back(s, -u);
        events.emplace_back(t, u);
    }
    events.emplace_back(86400, 0);

    auto sim = [&](ldouble x, ldouble f) -> ldouble {
        ldouble t = 0;
        for (auto [s, d] : events) {
            x = min(xmax, x + f * (s - t));
            if (x < 0) return -1;

            f += d;
            t = s;
        }
        return x;
    };

    auto judge = [&](ldouble f) {
        ldouble lim = sim(xmax, f);
        if (lim < 0) return false;
        return sim(lim, f) >= lim;
    };

    ldouble ng = 0, ok = 1e6;
    for (int q = 0; q < 50; ++q) {
        auto mid = (ok + ng) / 2;
        if (judge(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << endl;

    return true;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    while (solve()) {}

    return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 19604
final_rank: 19

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

using ll = long long;
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define POPCOUNT(x) __builtin_popcount(x)
template <typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void chmax(T &a, const T &b) { a = max(a, b); }

const ll INF = 1LL << 60;

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} fastiofastio;

int main() {
    while (1) {
        int N;
        double L;
        cin >> N >> L;
        if (N == 0)
            break;
        vector<int> s(N), t(N), u(N);
        for (int i = 0; i < N; i++) {
            cin >> s[i] >> t[i] >> u[i];
        }
        double low = 0, high = 1e6;
        for (int i = 0; i < 100; i++) {
            double mid = (low + high) / 2;
            double x = L;
            int prev = 0;
            bool ok = 1;
            for (int j = 0; j < N; j++) {
                x = min(x + (s[j] - prev) * mid, L);
                if (u[j] <= mid) {
                    x = min(x + (t[j] - s[j]) * (mid - u[j]), L);
                } else {
                    if ((t[j] - s[j]) * (u[j] - mid) > x) {
                        ok = 0;
                        break;
                    }
                    x -= (t[j] - s[j]) * (u[j] - mid);
                }
                prev = t[j];
            }
            double y = min(x + (86400 - prev) * mid, L);
            prev = 0;
            for (int j = 0; j < N; j++) {
                y = min(y + (s[j] - prev) * mid, L);
                if (u[j] <= mid) {
                    y = min(y + (t[j] - s[j]) * (mid - u[j]), L);
                } else {
                    if ((t[j] - s[j]) * (u[j] - mid) > y) {
                        ok = 0;
                        break;
                    }
                    y -= (t[j] - s[j]) * (u[j] - mid);
                }
                prev = t[j];
            }
            if (y < x)
                ok = 0;
            if (ok)
                high = mid;
            else
                low = mid;
        }
        cout << fixed << setprecision(15) << low << endl;
    }
}
accuracy: 1
time_ms: 160
memory_kb: 4224
final_rank: 4

code_snippet: #include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std;
int N;
double V;
int s[1<<17],t[1<<17],u[1<<17];
bool ok(double D)
{
	double now=V;
	for(int i=1;i<N;i++)
	{
		now+=D*(s[i]-t[i-1]);
		if(now>V)now=V;
		now-=(u[i]-D)*(t[i]-s[i]);
		if(now>V)now=V;
		if(now<0)return false;
	}
	double st=now;
	for(int i=1;i<N;i++)
	{
		now+=D*(s[i]-t[i-1]);
		if(now>V)now=V;
		now-=(u[i]-D)*(t[i]-s[i]);
		if(now>V)now=V;
		if(now<0)return false;
	}
	return abs(st-now)<1e-10;
}
main()
{
	while(cin>>N>>V,N)
	{
		s[0]=t[0]=0;
		s[N+1]=t[N+1]=86400;
		u[0]=u[N+1]=0;
		for(int i=1;i<=N;i++)cin>>s[i]>>t[i]>>u[i];
		N+=2;
		double L=0,R=1e6+1;
		for(int i=0;i<100;i++)
		{
			double mid=(L+R)/2;
			if(ok(mid))R=mid;
			else L=mid;
		}
		cout<<fixed<<setprecision(16)<<R<<endl;
	}
}
accuracy: 1
time_ms: 210
memory_kb: 4296
final_rank: 6

code_snippet: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

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

	while (cin >> N >> M,N) {
		vector<int>add(86401);
		long double sum = 0;
		while (N--) {
			cin >> L >> R >> K;
			sum += (R - L) * K;
			add[L] += K;
			add[R] -= K;
		}
		for (int i = 1; i <= 86400; i++) {
			add[i] += add[i - 1];
		}
		add.pop_back();
		long double l = 0, r = 1000000;
		for (int loop = 0; loop < 40; loop++) {
			long double mid = (r + l) / 2;
			long double stl = 0, str = M;
			bool ok = false;
			for (int looop = 0; looop < 40; looop++) {
				bool flag = true;
				long double stmid = (stl + str) / 2;
				long double st = stmid;
				for (auto i : add) {
					st -= i;
					st += mid;
					if (st < 0) {
						flag = false;
						break;
					}
					if (st > M)st = M;
				}
				if (flag) {
					str = stmid;
					if (stmid <= st) {
						ok = true;
						break;
					}
				}
				else stl = stmid;
			}
			if (ok)r = mid;
			else l = mid;
		}
		cout << fixed << setprecision(20) << max(sum/86400,l) << endl;
	}
}
accuracy: 1
time_ms: 7480
memory_kb: 3604
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
const double INF = 10000000;
const double EPS = 0.0000001;
int main(){
  cout << fixed << setprecision(8);
  while (1){
    int N;
    double L;
    cin >> N >> L;
    if (N == 0 && L == 0){
      break;
    }
    vector<int> s(N), t(N), u(N);
    for (int i = 0; i < N; i++){
      cin >> s[i] >> t[i] >> u[i];
    }
    vector<int> s2, t2, u2;
    s2.push_back(0);
    t2.push_back(s[0]);
    u2.push_back(0);
    for (int j = 0; j < N; j++){
      s2.push_back(s[j]);
      t2.push_back(t[j]);
      u2.push_back(u[j]);
      if (j < N - 1){
        s2.push_back(t[j]);
        t2.push_back(s[j + 1]);
        u2.push_back(0);
      }
    }
    s2.push_back(t[N - 1]);
    t2.push_back(86400);
    u2.push_back(0);
    int M = s2.size();
    double tv = INF;
    double fv = 0;
    for (int i = 0; i < 100; i++){
      double mid = (tv + fv) / 2;
      double V = L;
      double m = V;
      for (int j = 0; j < M; j++){
        V += (t2[j] - s2[j]) * (mid - u2[j]);
        V = min(V, L);
        m = min(m, V);
      }
      bool ok = true;
      if (m < 0){
        ok = false;
      } else {
        double V2 = V;
        for (int j = 0; j < M; j++){
          V2 += (t2[j] - s2[j]) * (mid - u2[j]);
          V2 = min(V2, L);
          m = min(m, V2);
        }
        if (m < 0 || V - V2 > EPS){
          ok = false;
        } else {
          ok = true;
        }
      }
      if (ok){
        tv = mid;
      } else {
        fv = mid;
      }
    }
    cout << tv << endl;
  }
}
accuracy: 1
time_ms: 240
memory_kb: 7280
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=1<<15,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;double L;cin>>N>>L;
        if(N==0) break;
        
        vector<double> X(86400*2);
        
        while(N--){
            int l,r;cin>>l>>r;
            double u;cin>>u;
            
            for(int i=l;i<r;i++){
                X[i]=u;
                X[86400+i]=u;
            }
        }
        
        double left=0,right=2e6;
        
        for(int q=0;q<100;q++){
            double mid=(left+right)/2.0;
            
            double now=L;
            
            double save;
            bool check=true;
            
            for(int t=0;t<86400*2;t++){
                now+=(mid-X[t]);
                if(now<0) check=false;
                
                chmin(now,L);
                
                if(t==86399) save=now;
            }
            
            if(save>now) check=false;
            
            if(check) right=mid;
            else left=mid;
        }
        
        cout<<fixed<<setprecision(25)<<right<<endl;
    }
}
accuracy: 1
time_ms: 2270
memory_kb: 4588
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(int i=0;i<((int)(v.size()));++i) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}
bool solve() {
  int n; double L; cin >> n >> L;
  if(n == 0) return false;
  int day = 86400;
  vector<int> s(n), t(n);
  vector<double> u(n);
  for(int i=0;i<(n);++i) {
    cin >> s[i] >> t[i] >> u[i];
  }
  vi sch(day);
  for(int i=0;i<(n);++i) {
    for(int j=(s[i]);j<(t[i]);++j) {
      sch[j] = u[i];
    }
  }
  double l = 0, r = 1000000;
  for(int i=0;i<(100);++i) {
    double mid = (l + r) / 2;
    bool ok = true;
    double now = L;
    for(int j=0;j<(day);++j) {
      now -= sch[j];
      now += mid;
      chmin(now, L);
      if(now < 0) {
        ok = false;
      }
    }
    double tmp = now;
    for(int j=0;j<(day);++j) {
      now -= sch[j];
      now += mid;
      chmin(now, L);
      if(now < 0) {
        ok = false;
      }
    }
    if(now < tmp) ok = false;
    if(ok) r = mid;
    else l = mid;
  }
  cout << l << endl;
  return true;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(1) {
    if(!solve()) {
      break;
    }
  }
}
accuracy: 1
time_ms: 3500
memory_kb: 4696
final_rank: 16

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PL;
typedef pair<int,int> P;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const double eps = 1e-6;
int N,L;
vector<int> S,T,U;

bool ok(double x){
    int t = 0;
    double tank = (double)L;
    rep(i,N){
        tank = min((double)L,tank + (S[i] - t)*x);
        t = S[i];
        tank = min((double)L,tank + (T[i] - t)*(x - U[i]));
        if (tank < 0) return false;
        t = T[i];
    }
    tank = min((double)L,tank + (86400 - t)*x);
    double one_day_tank = tank;
    t = 0;
    rep(i,N){
        tank = min((double)L,tank + (S[i] - t)*x);
        t = S[i];
        tank = min((double)L,tank + (T[i] - t)*(x - U[i]));
        if (tank < 0) return false;
        t = T[i];
    }
    tank = min((double)L,tank + (86400 - t)*x);
    return abs(one_day_tank - tank) < 1e-8;
}

void solve(){
    S.resize(N),T.resize(N),U.resize(N);
    rep(i,N) scanf("%d %d %d",&S[i],&T[i],&U[i]);
    double l = 0.0,r = 1e10;
    rep(_,150){
        double m = (r + l)/2;
        if (ok(m)) r = m;
        else l = m;
    }
    printf("%.10f\n",r);
}

int main() {
    while (1){
        scanf("%d %d",&N,&L);
        if (N == 0) return 0;
        solve();
    }
}
accuracy: 1
time_ms: 180
memory_kb: 3904
final_rank: 2

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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define all(x) begin(x),end(x)

#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    for (;;) {
        int N, L; cin >> N >> L;
        if (N == 0) break;

        const int MAX = 86400;

        vi s(N+2), t(N+2), u(N+2);
        REP(i, N) {
            cin >> s[i+1] >> t[i+1] >> u[i+1];
        }
        t[0] = 0, s[N+1] = MAX;

        auto check = [&](double rate) {
            double tank = L;
            double record[2];
            REP(k, 2) {
                REP(i, N) {
                    tank = min(tank + (s[i + 1] - t[i]) * rate, (double) L);
                    tank = min(tank + (t[i + 1] - s[i + 1]) * (rate - u[i+1]), (double) L);
                    if (tank < -eps) {
                        return false;
                    }
                }
                tank = min(tank + (s[N + 1] - t[N]) * rate, (double) L);
                record[k] = tank;
            }

            if (record[0] > record[1] + eps) {
                return false;
            }
            return true;
        };

        double l = 0, r = 1e6;
        while ((r - l) > eps) {
            double m = (l + r) / 2;
            if (check(m)) {
                r = m;
            } else {
                l = m;
            }
        }
        cout << r << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 4044
final_rank: 1