alexjercan/bugnet huggingface dataset:
Problem p01295 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define pi pair<int, int>
#define pb push_back
#define sec second
#define sh(i) (1LL << i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n, k;

int main() {
  while (cin >> n >> k && n) {
    n--;
    int cur = 1, d = 1, p = 10;
    while (1) {
      if (n - d < 0)
        break;
      n -= d;
      cur++;
      if (cur == p)
        d++, p *= 10;
    }
    string a;
    while (a.sz < k) {
      sst ss;
      ss << cur++;
      a += ss.str().substr(n);
      n = 0;
    }
    cout << a.substr(0, k) << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define pi pair<int, int>
#define pb push_back
#define sec second
#define sh(i) (1LL << i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n, k;

int d(int a) {
  if (a)
    return 1 + d(a / 10);
  return 0;
}

int main() {
  while (cin >> n >> k && n) {
    n--;
    int cur = 1;
    while (1) {
      if (n - d(cur) < 0)
        break;
      n -= d(cur++);
    }
    string a;
    while (a.sz < k) {
      sst ss;
      ss << cur++;
      a += ss.str().substr(n);
      n = 0;
    }
    cout << a.substr(0, k) << endl;
  }
}
Problem p01295 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

long long N, K;

long long count(long long n) {
  long long ans = 0;
  long long p = 9;
  long long l = 1;

  for (long long k = n; k >= 10; k /= 10, p *= 10, l++)
    ans += l * p;

  ans += l * (n - p / 9 + 1);
  return ans;
}

string make(long long v) {
  string ret;
  char tmp[50];
  for (long long i = 0; i < 100; i++) {
    sprintf(tmp, "%d", v + i);
    ret += tmp;
  }
  return ret;
}

int main(void) {
  while (1) {
    cin >> N >> K;
    if (N == 0 && K == 0)
      break;

    long long lb = -1, ub = 1000000001, mid;
    while (ub - lb > 1) {
      mid = (lb + ub) / 2;
      if (count(mid) < N)
        lb = mid;
      else
        ub = mid;
    }
    long long offset = N - count(lb);

    string s = make(ub);
    cout << s.substr(offset - 1, K) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int N, K;

int count(int n) {
  int ans = 0;
  int p = 9;
  int l = 1;

  for (int k = n; k >= 10; k /= 10, p *= 10, l++)
    ans += l * p;

  ans += l * (n - p / 9 + 1);
  return ans;
}

string make(int v) {
  string ret;
  char tmp[50];
  for (int i = 0; i < 100; i++) {
    sprintf(tmp, "%d", v + i);
    ret += tmp;
  }
  return ret;
}

int main(void) {
  while (1) {
    cin >> N >> K;
    if (N == 0 && K == 0)
      break;

    int lb = -1, ub = 1000000001, mid;
    while (ub - lb > 1) {
      mid = (lb + ub) / 2;
      if (count(mid) < N)
        lb = mid;
      else
        ub = mid;
    }
    int offset = N - count(lb);

    string s = make(ub);
    cout << s.substr(offset - 1, K) << endl;
  }
  return 0;
}
Problem p01295 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

typedef long long ll;

int main() {
  ll order[9];
  rep(i, 9) order[i] = (i + 1) * 9 * (ll)pow(10., i);

  for (int n, k; scanf("%d%d", &n, &k), n;) {
    int p;
    for (p = 0; p < 9; p++) {
      if (n <= order[p])
        break;
      n -= order[p];
    }

    int startnum = (int)pow(10., p) + (n - 1) / (p + 1);
    int startdgt = (n - 1) % (p + 1);
    char ans[1024] = "", tmp[1024];
    sprintf(tmp, "%d", startnum);
    strcat(ans, tmp + startdgt);
    for (int i = 0, j = startnum + 1; i < k; i += p + 1, j++) {
      sprintf(tmp, "%d", j);
      strcat(ans, tmp);
    }
    ans[k] = '\\0';
    puts(ans);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

typedef long long ll;

int main() {
  ll order[9];
  rep(i, 9) order[i] = (i + 1) * 9 * (ll)pow(10., i);

  for (int n, k; scanf("%d%d", &n, &k), n;) {
    int p;
    for (p = 0; p < 9; p++) {
      if (n <= order[p])
        break;
      n -= order[p];
    }

    int startnum = (int)pow(10., p) + (n - 1) / (p + 1);
    int startdgt = (n - 1) % (p + 1);
    char ans[128] = "", tmp[128];
    sprintf(tmp, "%d", startnum);
    strcat(ans, tmp + startdgt);
    for (int i = 0, j = startnum + 1; i < k; i += p + 1, j++) {
      sprintf(tmp, "%d", j);
      strcat(ans, tmp);
    }
    ans[k] = '\\0';
    puts(ans);
  }

  return 0;
}
Problem p01295 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
using namespace std;
// const int INF = 1e8;

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
  rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
  return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (T &x : v) {
    is >> x;
  }
  return is;
}

#define int long long

string solve(int k, int n) {
  string res = "";
  rep(i, 200) { res += to_string(i); }
  return res.substr(k, n);
}

string solve(int s, int k, int n) {
  string res = "";
  for (int i = s; res.size() < k + 200; i++) {
    res += to_string(i);
  }
  return res.substr(k, n);
}

signed main() {
  int k, n;
  while (cin >> k >> n, k || n) {
    if (k <= 10) {
      cout << solve(k, n) << endl;
      continue;
    }

    int i = 2;
    int t = 10, q = 100, d = 10;
    int idx = 10;
    while (k > idx + (q - d) * i) {
      idx += (q - d) * i;
      t += q - d;
      q *= 10;
      d *= 10;
      i++;
    }

    int diff = k - idx;
    int times = diff / i;
    // cout << t + times << ' ' << diff % i << endl;
    cout << solve(t + times, diff % i, n) << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
using namespace std;
// const int INF = 1e8;

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
  rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
  return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (T &x : v) {
    is >> x;
  }
  return is;
}

string solve(int k, int n) {
  string res = "";
  rep(i, 200) { res += to_string(i); }
  assert(res.size() > k + n);
  return res.substr(k, n);
}

string solve(int s, int k, int n) {
  string res = "";
  for (int i = s; res.size() < k + 200; i++) {
    res += to_string(i);
  }
  return res.substr(k, n);
}

int main() {
  int k, n;
  while (cin >> k >> n, k || n) {
    if (k <= 10) {
      cout << solve(k, n) << endl;
      continue;
    }

    int i = 2;
    int t = 10, q = 99, d = 10;
    int idx = 10;
    while (k > t + (q - d + 1) * i) {
      q *= 10;
      q += 9;
      d *= 10;
      idx += (q - d + 1) * i;
      t += q - d + 1;
      i++;
    }

    int diff = k - idx;
    int times = diff / i;
    // cout << t + times << ' ' << diff % i << endl;
    cout << solve(t + times, diff % i, n) << endl;
  }
}
Problem p01295 (C++) — buggy submission, verdict: Time Limit Exceeded

// {{{ include
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
// }}}
#include <sstream>

using namespace std;

typedef long long ll;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}

ll sumd(ll v) {
  v--;

  ll ten = 1;
  int lgt = 0;
  while (ten * 10 <= v) {
    ten *= 10;
    lgt++;
  }
  ll sum = 0;
  while (v) {
    sum += (v - ten + 1) * (lgt + 1);
    v = ten - 1;
    ten /= 10;
    lgt--;
  }
  return sum;
}

bool is_ok(ll v, ll n) { return sumd(v) < n; }

int main() {
  ll N;
  int K;
  while (N = in(), K = in()) {
    ll l = 1;
    ll r = N + 1;
    while (r - l > 1) {
      ll m = l + r >> 1;
      if (is_ok(m, N))
        l = m;
      else
        r = m;
    }
    ll offset = N - sumd(l);
    stringstream ss;
    for (int i = 0; i < K; i++) {
      ss << l + i;
    }
    string S = ss.str();
    cout << S.substr(offset - 1, K) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

// {{{ include
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
// }}}
#include <sstream>

using namespace std;

typedef long long ll;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}

ll sumd(ll v) {
  ll ten = 1;
  int lgt = 0;
  while (ten * 10 <= v) {
    ten *= 10;
    lgt++;
  }
  ll sum = 0;
  while (v) {
    sum += (v - ten + 1) * (lgt + 1);
    v = ten - 1;
    lgt--;
  }
  return sum;
}

bool is_ok(ll v, ll n) { return sumd(v) < n; }

int main() {
  ll N;
  int K;
  while (N = in(), K = in()) {
    ll l = 1;
    ll r = N + 1;
    while (r - l > 1) {
      ll m = l + r >> 1;
      if (is_ok(m, N))
        l = m;
      else
        r = m;
    }
    stringstream ss;
    for (int i = 0; i <= K; i++) {
      ss << l + i;
    }
    ll offset = N - sumd(l);
    string S = ss.str();
    cout << S.substr(offset, K) << endl;
  }
  return 0;
}
Problem p01296 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>

using namespace std;

int x[20000], y[20000];
char dir[20000];
int p[20000];
vector<vector<int>> G;

int dst(int x1, int y1, int x2, int y2) { return abs(x1 - x2) + abs(y1 - y2); }

bool dfs(int v) {
  for (auto e : G[v]) {
    int sp = (dst(x[v], y[v], x[e], y[e]) == 2) ? -1 : 1;
    if (p[e] == 0) {
      p[e] = sp * p[v];
      if (!dfs(e))
        return false;
    } else {
      if (p[e] * p[v] != sp)
        return false;
    }
  }
  return true;
}

int main() {
  for (int n; cin >> n, n;) {
    for (int i = 0; i < n; i++) {
      cin >> x[i] >> y[i] >> dir[i];
    }
    G = vector<vector<int>>(n);
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (min({dst(x[i], y[i], x[j], y[j]),
                 dst(x[i], y[i], x[j] + (dir[j] == 'x'),
                     y[j] + (dir[j] == 'y')),
                 dst(x[i] + (dir[i] == 'x'), y[i] + (dir[i] == 'y'), x[j],
                     y[j]),
                 dst(x[i] + (dir[i] == 'x'), y[i] + (dir[i] == 'y'),
                     x[j] + (dir[j] == 'x'), y[j] + (dir[j] == 'y'))}) == 1) {
          G[i].push_back(j);
          G[j].push_back(i);
        }
      }
    }
    fill(begin(p), end(p), 0);
    bool f = false;
    for (int i = 0; i < n; i++) {
      if (p[i] == 0) {
        p[i] = 1;
      }
      f |= !dfs(i);
    }
    cout << (f ? "No" : "Yes") << endl;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>

using namespace std;

int x[20000], y[20000];
char dir[20000];
int p[20000];
vector<vector<int>> G;

int dst(int x1, int y1, int x2, int y2) { return abs(x1 - x2) + abs(y1 - y2); }

bool dfs(int v) {
  for (auto e : G[v]) {
    int sp = (dst(x[v], y[v], x[e], y[e]) == 2) ? -1 : 1;
    if (p[e] == 0) {
      p[e] = sp * p[v];
      if (!dfs(e))
        return false;
    } else {
      if (p[e] * p[v] != sp)
        return false;
    }
  }
  return true;
}

int main() {
  for (int n; cin >> n, n;) {
    for (int i = 0; i < n; i++) {
      cin >> x[i] >> y[i] >> dir[i];
    }
    G = vector<vector<int>>(n);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i == j)
          continue;
        if (min({dst(x[i], y[i], x[j], y[j]),
                 dst(x[i], y[i], x[j] + (dir[j] == 'x'),
                     y[j] + (dir[j] == 'y')),
                 dst(x[i] + (dir[i] == 'x'), y[i] + (dir[i] == 'y'), x[j],
                     y[j]),
                 dst(x[i] + (dir[i] == 'x'), y[i] + (dir[i] == 'y'),
                     x[j] + (dir[j] == 'x'), y[j] + (dir[j] == 'y'))}) == 1) {
          G[i].push_back(j);
        }
      }
    }
    fill(begin(p), end(p), 0);
    bool f = false;
    for (int i = 0; i < n; i++) {
      if (p[i] == 0) {
        p[i] = 1;
      }
      f |= !dfs(i);
    }
    cout << (f ? "No" : "Yes") << endl;
  }
}
Problem p01296 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
char c;
int x[20001][2], y[20001][2];
vector<int> v[40001];
int b[40001], f, n;
void dfs(int p, int col) {
  b[p] = col;
  r(i, v[p].size()) {
    if (!(p == v[p][i] + n || p + n == v[p][i]) && b[v[p][i]] &&
        b[v[p][i]] != col)
      f++;
    else if (!b[v[p][i]]) {
      if (p == v[p][i] + n || p + n == v[p][i]) {
        if (col == 1)
          dfs(v[p][i], 2);
        else
          dfs(v[p][i], 1);
      } else
        dfs(v[p][i], col);
    }
  }
}
int main() {
  while (cin >> n, n) {
    memset(b, 0, sizeof(b));
    r(i, 40001) v[i].clear();
    r(i, n) {
      cin >> x[i][0] >> y[i][0] >> c;
      if (c == 'x')
        x[i][1] = x[i][0] + 1, y[i][1] = y[i][0];
      else
        x[i][1] = x[i][0], y[i][1] = y[i][0] + 1;
    }
    r(i, n) v[i].push_back(i + n), v[i + n].push_back(i);
    r(i, n) r(j, n) if (i != j && i < j) r(l, 2) r(k, 2) {
      if (abs(x[i][l] - x[j][k]) + abs(y[i][l] - y[j][k]) == 1) {
        int p1 = i, p2 = j;
        if (l)
          p1 += n;
        if (k)
          p2 += n;
        v[p1].push_back(p2);
        v[p2].push_back(p1);
      }
    }
    f = 0;
    r(i, n * 2) if (!b[i]) dfs(i, 1);
    cout << (f ? "No" : "Yes") << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
char c;
int x[20001][2], y[20001][2];
vector<int> v[40001];
int b[40001], f, n;
void dfs(int p, int col) {
  b[p] = col;
  r(i, v[p].size()) {
    if (!(p == v[p][i] + n || p + n == v[p][i]) && b[v[p][i]] &&
        b[v[p][i]] != col)
      f++;
    else if (!b[v[p][i]]) {
      if (p == v[p][i] + n || p + n == v[p][i]) {
        if (col == 1)
          dfs(v[p][i], 2);
        else
          dfs(v[p][i], 1);
      } else
        dfs(v[p][i], col);
    }
  }
}
int main() {
  while (cin >> n, n) {
    memset(b, 0, sizeof(b));
    r(i, 40001) v[i].clear();
    r(i, n) {
      cin >> x[i][0] >> y[i][0] >> c;
      if (c == 'x')
        x[i][1] = x[i][0] + 1, y[i][1] = y[i][0];
      else
        x[i][1] = x[i][0], y[i][1] = y[i][0] + 1;
    }
    r(i, n) v[i].push_back(i + n), v[i + n].push_back(i);
    r(i, n) r(j, n) if (i != j && i < j) r(l, 2) r(k, 2) {
      if (abs(x[i][l] - x[j][k]) + abs(y[i][l] - y[j][k]) == 1) {
        int p1 = i, p2 = j;
        if (l)
          p1 += n;
        if (k)
          p2 += n;
        v[p1].push_back(p2);
        v[p2].push_back(p1);
      } else if (abs(x[i][l] - x[j][k]) == 3 && abs(y[i][l] - y[j][k]) == 0) {
        int p1 = i, p2 = j;
        if (l)
          p1 += n;
        if (k)
          p2 += n;
        v[p1].push_back(p2);
        v[p2].push_back(p1);
      }
      if (abs(x[i][l] - x[j][k]) == 0 && abs(y[i][l] - y[j][k]) == 3) {
        int p1 = i, p2 = j;
        if (l)
          p1 += n;
        if (k)
          p2 += n;
        v[p1].push_back(p2);
        v[p2].push_back(p1);
      }
    }
    f = 0;
    r(i, n * 2) if (!b[i]) dfs(i, 1);
    cout << (f ? "No" : "Yes") << endl;
  }
}
Problem p01298 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define EPS (1e-10)
#define EQ(a, b) ((abs((a) - (b))) < EPS)

int a[100001];
int n, l;

bool check(double f) {
  double lf = l;
  double rec = 0;
  bool flag = false;
  for (int j = 0; j < 3; j++) {
    for (int i = 1; i <= 86400; i++) {
      if (j == 1 && a[i] != 0 && !flag) {
        rec = lf;
        flag = true;
      } else if (j == 2 && a[i] != 0) {
        if (EQ(rec, lf))
          return true;
        return false;
      }
      double b = -a[i] + f;
      lf += b;
      if (EQ(lf, 0) || lf < 0)
        return false;
      lf = min(lf, 1.0 * l);
    }
  }
  return true;
}

int main() {

  while (cin >> n >> l && !(n == 0 && l == 0)) {
    memset(a, 0, sizeof(a));
    int s, t, u;
    for (int j = 0; j < n; j++) {
      cin >> s >> t >> u;
      for (int i = s + 1; i <= t; i++)
        a[i] = u;
    }
    double ub = 10000000;
    double lb = 0;
    int cnt = 80;
    while (cnt--) {
      double mid = (ub + lb) / 2;
      if (check(mid))
        ub = mid;
      else
        lb = mid;
    }
    printf("%.10f\\n", ub);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define EPS (1e-10)
#define EQ(a, b) ((abs((a) - (b))) < EPS)

int a[100001];
int n, l;

bool check(double f) {
  double lf = l;
  double rec = 0;
  bool flag = false;
  for (int j = 0; j < 3; j++) {
    for (int i = 1; i <= 86400; i++) {
      if (j == 1 && a[i] != 0 && !flag) {
        rec = lf;
        flag = true;
      } else if (j == 2 && a[i] != 0) {
        if (EQ(rec, lf))
          return true;
        return false;
      }
      double b = -a[i] + f;
      lf += b;
      if (EQ(lf, 0) || lf < 0)
        return false;
      lf = min(lf, 1.0 * l);
    }
  }
  return true;
}

int main() {

  while (cin >> n >> l && !(n == 0 && l == 0)) {
    memset(a, 0, sizeof(a));
    int s, t, u;
    for (int j = 0; j < n; j++) {
      cin >> s >> t >> u;
      for (int i = s + 1; i <= t; i++)
        a[i] = u;
    }
    double ub = 10000000;
    double lb = 0;
    int cnt = 100;
    while (cnt--) {
      double mid = (ub + lb) / 2;
      if (check(mid))
        ub = mid;
      else
        lb = mid;
    }
    printf("%.10f\\n", ub);
  }
  return 0;
}
Problem p01298 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define EPS (1e-10)
#define EQ(a, b) ((abs((a) - (b))) < EPS)

int a[100001];
int n, l;

bool check(double f) {
  double lf = l;
  double rec = 0;
  //	if(f>=0.4&&f<=0.45){
  //		cout<<endl;
  //	}
  // bool flag=false;
  for (int j = 0; j < 3; j++) {
    for (int i = 1; i <= 86400; i++) {
      if (j == 1 && i == 1) {
        rec = lf;
      }
      if (j == 2 && i == 1) {
        if (EQ(rec, lf) || rec < lf)
          return true;
        return false;
      }
      //			if(j==1&&a[i]!=0&&!flag){
      //				rec=lf;
      //				flag=true;
      //			}
      //			else if(j==2&&a[i]!=0){
      //				if(EQ(rec,lf))return true;
      //				return false;
      //			}
      double b = -a[i] + f;
      lf += b;
      if (EQ(lf, 0) || lf < 0)
        return false;
      lf = min(lf, 1.0 * l);
    }
  }
  return true;
}

int main() {

  while (cin >> n >> l && !(n == 0 && l == 0)) {
    memset(a, 0, sizeof(a));
    int s, t, u;
    for (int j = 0; j < n; j++) {
      cin >> s >> t >> u;
      for (int i = s + 1; i <= t; i++)
        a[i] = u;
    }
    double ub = 10000000;
    double lb = 0;
    int cnt = 100;
    while (cnt--) {
      double mid = (ub + lb) / 2;
      if (check(mid))
        ub = mid;
      else
        lb = mid;
    }
    printf("%.10f\\n", ub);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define EPS (1e-10)
#define EQ(a, b) ((abs((a) - (b))) < EPS)

int a[100001];
int n, l;

bool check(double f) {
  double lf = l;
  double rec = 0;
  bool flag = false;
  for (int j = 0; j < 3; j++) {
    for (int i = 0; i <= 86400; i++) {
      if (j == 1 && a[i] != 0 && !flag) {
        rec = lf;
        flag = true;
      } else if (j == 2 && a[i] != 0) {
        if (EQ(rec, l))
          return true;
        return false;
      }
      double b = -a[i] + f;
      lf += b;
      if (EQ(lf, 0) || lf < 0)
        return false;
      lf = min(lf, 1.0 * l);
    }
  }
  return true;
}

int main() {

  while (cin >> n >> l && !(n == 0 && l == 0)) {
    memset(a, 0, sizeof(a));
    int s, t, u;
    for (int j = 0; j < n; j++) {
      cin >> s >> t >> u;
      for (int i = s; i <= t; i++)
        a[i] = u;
    }
    double ub = 1000000;
    double lb = 0;
    int cnt = 150;
    while (cnt--) {
      double mid = (ub + lb) / 2;
      if (check(mid))
        ub = mid;
      else
        lb = mid;
    }
    printf("%.10f\\n", ub);
  }
  return 0;
}