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

#include <iostream>

using namespace std;
typedef long long int ll;

int main() {
  ll e;
  while (cin >> e, e != 0) {
    ll mm = 99999999;

    ll z[101];
    ll zn = 0;
    for (ll i = 0; i <= 100; ++i) {
      z[zn] = e - i * i * i;
      ++zn;
    }

    for (ll i = 0; i <= 100 * 100 * 100; ++i) {
      for (ll j = 0; j < zn; ++j) {
        if (z[j] - i * i < 0)
          break;

        ll const vy = i * i;
        ll const vz = -(z[j] - e);
        ll const vx = z[j] - vy;

        if (vx + vy + vz != e)
          break;

        if (i + j + vx < mm) {
          mm = i + j + vx;
        }
      }
    }
    cout << mm << endl;
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <queue>

using namespace std;

int main() {
  unsigned long long e;
  while (cin >> e) {
    if (e == 0)
      break;

    priority_queue<unsigned int, vector<unsigned int>, greater<unsigned int>> q;
    [&]() mutable -> void {
      const unsigned short y_max = sqrt(e);
      const unsigned short z_max = cbrt(e);
      for (unsigned int x = 0; x <= e; ++x) {
        for (unsigned short y = 0; y <= y_max; ++y) {
          for (unsigned short z = 0; z <= z_max; ++z) {
            unsigned long long const v = x + y * y + z * z * z;
            if (v > e)
              break;
            if (v == e) {
              if (q.size() == 20)
                return;

              q.push(x + y + z);
            }
          }
        }
      }
    }();

    cout << q.top() << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <utility>
using namespace std;

int main(void) {

  int e;

  while (1) {
    cin >> e;
    int ans = 100000000;
    if (e == 0)
      break;
    for (int y = 0; y <= sqrt(e) + 1; y++) {
      for (int z = 0; z <= cbrt(e) + 1; z++) {
        int x = e - y * y - z * z * z;
        if (e == x + y * y + z * z * z && x >= 0) {
          ans = min(ans, x + y + z);
          // cout << x << ' ' << y << ' ' << z << endl;
        }
      }
    }

    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <utility>
using namespace std;

int main(void) {

  int e;

  while (1) {
    cin >> e;
    int ans = e;
    if (e == 0)
      break;
    for (int y = 0; y <= sqrt(e); y++) {
      for (int z = 0; z <= pow(e, 1.0 / 3.0); z++) {
        int x = e - y * y - z * z * z;
        if (e == x + y * y + z * z * z && x >= 0) {
          ans = min(ans, x + y + z);
          // cout << x << ' ' << y << ' ' << z << endl;
        }
      }
    }

    cout << ans << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main() {
  int e;
  while (cin >> e, e) {
    vector<int> dp(e + 1, e);
    vector<int> z;
    for (int i = 0; i * i * i <= e; i++) {
      z.push_back(i * i * i);
    }
    int z_size = z.size();
    for (int i = 0; i < z_size; i++) {
      for (int j = 0; z[i] + j * j <= e; j++) {
        int yy = j * j;
        dp[z[i] + yy] = min(i + j, dp[z[i] + yy]);
        dp[e] = min(e - z[i] - yy + dp[z[i] + yy], dp[e]);
      }
    }
    cout << dp[e] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main() {
  int e;
  while (cin >> e, e) {
    vector<int> dp(e + 1, e);
    for (int i = 0; i * i * i <= e; i++) {
      int zzz = i * i * i;
      dp[zzz] = min(i, dp[zzz]);
      for (int j = 0; zzz + j * j <= e; j++) {
        int yy = j * j;
        dp[zzz + yy] = min(i + j, dp[zzz + yy]);
        for (int k = 0; zzz + yy + k <= e; k++)
          dp[zzz + yy + k] = min(i + j + k, dp[zzz + yy + k]);
      }
    }
    cout << dp[e] << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int e;

  while (cin >> e, e) {
    int min_a = 1000000;
    int z_, y_;

    for (int z = 0; z * z * z <= e; z++)
      for (int y = 0; y * y + z * z * z <= e; y++) {
        if (min_a > z + y + e - y * y - z * z * z) {
          min_a = z + y + e - y * y - z * z * z;
          z_ = z;
          y_ = y;
        }
      }
    cout << e - y_ * y_ - z_ * z_ * z_ + y_ + z_ << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int e;

  while (cin >> e, e) {
    for (int x = 0; x <= e; x++)
      for (int y = 0; y <= e; y++)
        for (int z = 0; z <= e; z++)
          if (x + y * y + z * z * z == e) {
            cout << x + y + z << endl;
            goto out;
          }
  out:;
  }

  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int INF = 1e+8;
const int E_MAX = 1000000;

int main() {
  int e;
  while (cin >> e && e) {
    int ans = INF;
    for (int z = 0; z * z * z <= E_MAX; ++z) {
      if (z > e)
        break;
      for (int y = 0; y * y <= E_MAX; ++y) {
        if (z * z * z + y * y > e)
          break;
        ans = min(ans, z + y + (e - (y * y + z * z * z)));
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

const int INF = 1e+8;

int main() {
  int e;
  while (cin >> e && e) {
    int ans = INF;
    for (int x = 0; x <= 1000000; ++x) {
      if (x > ans)
        break;
      for (int y = 0; y * y <= 1000000; ++y) {
        if (x + y > ans)
          break;
        for (int z = 0; z * z * z <= 1000000; ++z) {
          if (x + y + z > ans)
            break;
          if ((x + y * y + z * z * z) == e) {
            ans = x + y + z;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int e;
  while (cin >> e, e) {
    int num;
    int ans = 1e9;
    for (int i = 0; i < e; i++) {
      if (i * i * i > e)
        break;
      for (int j = 0; j < e; j++) {
        num = e - i * i * i - j * j;
        if (num < 0)
          break;
        ans = min(ans, num + i + j);
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int e;
  while (cin >> e, e) {
    int num;
    int ans = 1e9;
    for (int i = 0; i < e; i++) {
      for (int j = 0; j < e; j++) {
        num = e - i * i * i - j * j;
        if (num < 0)
          break;
        ans = min(ans, num + i + j);
      }
    }
    cout << ans << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"

#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define RFOR(i, m, n) for (int i = n - 1; i >= m; --i)
#define ALL(v) v.begin(), v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while (1) {
    int e, ans = INF;
    cin >> e;
    if (!e)
      break;
    for (int i = 0; i * i * i <= e; ++i) {
      int y = sqrt(e - i * i * i);
      int x = e - i * i * i - y * y;
      ans = min(ans, x + y + i);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"

#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define RFOR(i, m, n) for (int i = n - 1; i >= m; --i)
#define ALL(v) v.begin(), v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while (1) {
    int e, ans = INF;
    cin >> e;
    int c = e;
    if (!e)
      break;
    REP(i, 101) {
      REP(j, 1000) {
        if (pow(j, 2) + pow(i, 3) > e)
          break;
        REP(k, 2 * j + 1) {
          if (k + pow(j, 2) + pow(i, 3) > e)
            break;
          if (k + pow(j, 2) + pow(i, 3) == e) {
            ans = min(ans, i + j + k);
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
// #include<limits.h>
using namespace std;
int solve(int E) {
  int ans = 999999;
  for (int z = 0; z * z * z <= E; z++)
    for (int y = 0; y * y <= E; y++) {
      // cout<<"z="<<z<<" y="<<y<<endl;
      int x = E - z * z * z - y * y;
      // cout<<"x="<<x<<endl;
      // cout<<"x+y*y+z*z*z="<<x+y*y+z*z*z<<endl;
      if ((x + y * y + z * z * z == E) && (x >= 0)) {

        if ((x + y + z) < ans) {
          ans = x + y + z;
          // cout<<"ans="<<ans<<endl;
        }
      }
    }
  return ans;
}
int main() {
  int E;
  while (cin >> E && E > 0) {
    cout << solve(E) << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <limits.h>
#include <math.h>
using namespace std;
int count = 0;
int solve(int E) {
  int ans = 1000;
  for (int x = 0; x <= E; ++x)
    for (int y = 0; y * y <= E; ++y) {
      // cout<<"y="<<y<<endl;
      int z = (int)round(pow(E - x - y * y, 1.0 / 3));
      // cout<<"z="<<z<<endl;
      if (x + y * y + z * z * z == E) {
        if ((x + y + z) < ans) {
          ans = x + y + z;
          // cout<<ans<<endl;
        }
      }
    }
  return ans;
}
int main() {
  int E;
  while (cin >> E && E > 0) {
    cout << solve(E) << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <fstream>
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int limit(int lim, int exp) {
  int res = 0;
  for (int i = 0; pow(i, exp) < lim + 1; i++) {
    res = i;
  }
  return res;
}

int main(void) {
  int e;
  cin >> e;

  while (e != 0) {
    int m = 0;
    int res;
    int en = e;
    int temp;
    int z = limit(en, 3);

    for (int i = 0; i < 10 && !((z - i) < 0); i++) {
      m = 0;
      en = e;

      m += z - i;
      en -= pow(z - i, 3);

      temp = limit(en, 2);
      m += temp;
      en -= pow(temp, 2);

      temp = limit(en, 1);
      m += temp;

      if (i == 0) {
        res = m;
      } else if (m < res) {
        res = m;
      }
    }

    temp = limit(e, 2);
    if (temp < res) {
      if (pow(temp, 2) == e) {
        res = temp;
      }
    }

    cout << res << endl;
    cin >> e;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int limit(int lim, int exp) {
  int res = 0;
  if (exp > 1) {
    for (int i = 2; pow(i, exp) < lim + 1; i++) {
      res = i;
    }
  } else {
    for (int i = 0; pow(i, exp) < lim + 1; i++) {
      res = i;
    }
  }
  return res;
}

int main(void) {
  int e;
  cin >> e;

  while (e != 0) {
    int lim = 0;
    int m = 0;
    int n = 0;
    int en = e;
    int temp;

    temp = limit(en, 3);
    lim += temp;
    en -= pow(temp, 3);

    temp = limit(en, 2);
    lim += temp;
    en -= pow(temp, 2);

    temp = limit(en, 1);
    lim += temp;
    m = lim;

    for (int x = 0; x < lim; x++) {
      for (int y = 0; y < (lim - x); y++) {
        for (int z = 0; z < (lim - x - y); z++) {
          n = x + y + z;
          if (n < m) {
            if ((x + pow(y, 2) + pow(z, 3)) == e) {
              m = n;
            }
          }
        }
      }
    }

    cout << m << endl;
    cin >> e;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#define min(a, b) a > b ? b : a

int pow(int n, int m) {
  int sum = 1;
  for (int i = 0; i < m; i++)
    sum *= n;
  return sum;
}

int main(void) {
  int y, z, e, m;
  while (1) {
    scanf("%d", &e);
    if (e == 0)
      break;
    m = 0x7FFFFFFF;
    for (z = 0; pow(z, 3) <= e; z++) {
      for (y = 0; pow(y + 1, 2) <= e - pow(z, 3); y++)
        ;
      m = min((z + y + (e - pow(z, 3) - pow(y, 2))), m);
    }
    printf("%d\\n", m);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <math.h>
#include <stdio.h>
#define min(a, b) a > b ? b : a

int main(void) {
  int y, z, e, m;
  while (1) {
    scanf("%d", &e);
    if (e == 0)
      break;
    m = 0x7FFFFFFF;
    for (z = 0; (int)pow((double)z, 3) <= e; z++) {
      for (y = 0; (int)pow((double)y + 1, 2) <= e - (int)pow((double)z, 3); y++)
        ;
      m = min((int)(z + y + (e - pow((double)z, 3) - pow((double)y, 2))), m);
    }
    printf("%d\\n", m);
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
  int E, z, y, x;
  while (cin >> E && E > 0) {
    if (E > 1000000) {
      cout << "Incorrect input" << endl;
      exit(1);
    }
    int min = 10000000;
    for (z = 0; z * z * z <= E; z++) {
      for (y = 0; y * y + z * z * z <= E; y++) {
        x = E - y * y - z * z * z;
        if (min > x + y + z)
          min = x + y + z;
      }
    }
    cout << min << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
  int E, tmp, z, y, x, i;
  for (;;) {
    cin >> E;
    if (E < 0 || E > 1000000) {
      cout << "Incorrect input" << endl;
      exit(1);
    }
    for (i = 0; i * i * i < E; i++) {
    }
    i--;
    z = i;
    tmp = E - z * z * z;
    for (i = 0; i * i < tmp; i++) {
    }
    i--;
    y = i;
    x = tmp - y * y;
    cout << x + y + z << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
// #include<math.h>
#define MAX 1000000
using namespace std;
void minn(int e) {
  int t = 0;
  int mi[MAX] = {0};
  for (int z = 0; z * z * z <= e; z++)
    for (int y = 0; y * y <= e - z * z * z; y++) {
      int x = e - z * z * z - y * y;
      // cout<<x<<y<<z<<endl;
      mi[t++] = x + y + z;
    }
  sort(mi, mi + t);
  cout << mi[0] << endl;
}
int main() {
  int e;
  while (cin >> e) {
    if (e == 0)
      break;
    minn(e);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#define MAX 1000000
using namespace std;
void minn(int e) {
  int t = 0;
  long int mi[MAX] = {0};
  for (int z = 0; z <= pow(e, 1.0 / 3); z++)
    for (int y = 0; y <= pow(e - z * z * z, 1.0 / 2); y++) {
      int x = e - z * z * z - y * y;
      // cout<<x<<y<<z<<endl;
      mi[t++] = x + y + z;
    }
  sort(mi, mi + t);
  cout << mi[0] << endl;
}
int main() {
  int e;
  while (cin >> e) {
    if (e == 0)
      break;
    minn(e);
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int e;
  while (cin >> e, e) {
    int ret = 1e6;
    for (int z = 0; z * z * z <= e; ++z) {
      int y = (int)pow(e - z * z * z, 1.0 / 2.0);
      int x = e - z * z * z - y * y;
      ret = min(ret, x + y + z);
    }
    cout << ret << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int e;
  while (cin >> e, e) {
    int ret = 1e6;
    for (int z = 0; z <= e; ++z) {
      int y = (int)pow(e - z * z * z, 1.0 / 2.0);
      int x = e - z * z * z - y * y;
      ret = min(ret, x + y + z);
    }
    cout << ret << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
#define INF 1000000
int main() {
  int e;
  vector<int> y, z;
  for (int i = 0;; i++) {
    if (i * i > INF)
      break;
    y.push_back(i * i);
  }
  for (int i = 0;; i++) {
    if (i * i * i > INF)
      break;
    z.push_back(i * i * i);
  }
  while (scanf("%d", &e)) {
    if (e == 0)
      break;
    int m = INF + 1;
    for (int i = 0; i < y.size(); i++) {
      if (y[i] > e)
        break;
      for (int j = 0; j < z.size(); j++) {
        if (z[j] > e)
          break;
        if (y[i] + z[j] > e)
          break;
        m = min(m, e - y[i] - z[j] + i + j);
      }
    }
    printf("%d\\n", m);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
#define INF 1000000
int main() {
  int e;
  vector<int> y, z;
  for (int i = 0;; i++) {
    if (i * i > INF)
      break;
    y.push_back(i * i);
  }
  for (int i = 0;; i++) {
    if (i * i * i > INF)
      break;
    z.push_back(i * i * i);
  }
  while (scanf("%d", &e)) {
    if (e == 0)
      break;
    int m = INF + 1;
    for (int x = 0; x <= e; x++) {
      for (int i = 0; i < y.size(); i++) {
        if (y[i] > e)
          break;
        for (int j = 0; j < z.size(); j++) {
          if (z[j] > e)
            break;
          if (e == x + y[i] + z[j])
            m = min(m, x + i + j);
        }
      }
    }
    printf("%d\\n", m);
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define ll long long
#define inf 1000000000
using namespace std;

int e;

int yy(int a) {
  int i = 0;
  while (i * i <= a) {
    if (i * i == a)
      return i;
    i++;
  }
  return inf;
}

int zzz(int a) {
  int i = 0;
  while (i * i * i <= a) {
    if (i * i * i == a)
      return i;
    i++;
  }
  return inf;
}

int main() {
  while (cin >> e, e) {
    int ans = inf;
    for (int i = 0; i * i * i <= e; i++) {
      for (int j = 0; j * j <= e; j++) {
        if (i * i * i + j * j <= e) {
          ans = min(ans, i + j + (e - i * i * i - j * j));
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define ll long long
#define inf 1000000000
using namespace std;

int e;

int yy(int a) {
  int i = 0;
  while (i * i <= a) {
    if (i * i == a)
      return i;
    i++;
  }
  return inf;
}

int zzz(int a) {
  int i = 0;
  while (i * i * i <= a) {
    if (i * i * i == a)
      return i;
    i++;
  }
  return inf;
}

int main() {
  while (cin >> e, e) {
    int ans = inf;
    for (int i = 0; i <= e; i++) {
      for (int j = 0; j <= e; j++) {
        if (i + j <= e) {
          ans = min(ans, i + yy(j) + zzz(e - i - j));
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <vector>

using namespace std;

int count = 0; // ?¨???¬??¨ global ?????°
int solve(int E) {
  ::count = 0;
  int ans = numeric_limits<int>::max(); // ?????§???
  for (int y = 0; y * y <= E; ++y) {
    for (int z = 0; z * z * z <= E; ++z) {
      ++::count;
      int x = (int)round(E - y * y - z * z * z);
      if (x + y * y + z * z * z == E && x >= 0)
        ans = min(ans, x + y + z);
    }
  }
  return ans;
}
int main() {
  int E;
  while (cin >> E && E > 0) {
    cout << solve(E) << endl;
    // cout << "case: m = " << E << " count: " << ::count << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <vector>

using namespace std;

int count = 0; // ?¨???¬??¨ global ?????°
int solve(int E) {
  // ?????´????±???????
  int ans = numeric_limits<int>::max(); // ?????§???
  for (int x = 0; x <= E; ++x) {
    for (int y = 0; y * y <= E; ++y) {
      int z = (int)round(pow(E - x - y * y, 1.0 / 3));
      if (x + y * y + z * z * z == E)
        ans = min(ans, x + y + z);
    }
  }
  return ans;
}
int main() {
  int E;
  while (cin >> E && E > 0) {
    cout << solve(E) << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int a;
  while (cin >> a, a) {
    int s = 1 << 29;
    for (int x = 0;; x++) {
      if (x * x * x > a)
        break;
      int y = sqrt(a - x * x * x);
      s = min(s, x + y + a - x * x * x - y * y);
    }
    cout << s << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

signed main() {
  int a;
  while (cin >> a, a) {
    int s = 1 << 29;
    for (int x = 0; x < a; x++) {
      for (int y = 0;; y++) {
        for (int z = 0;; z++) {
          if (x + y * y + z * z * z == a)
            s = min(s, x + y + z);
          if (x + y * y + z * z * z > a)
            break;
        }
        if (x + y * y > a)
          break;
      }
    }
    cout << s << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;
int E;
int main() {
  while (cin >> E && E > 0) {
    int m = 1000000;
    for (int z = 0; z * z * z <= E; z++) {
      // if(z >= m) break;
      for (int y = 0; y * y <= E - z * z * z; y++) {
        // if (y+z >= m) break;
        int x = E - z * z * z - y * y;
        if (x >= 0) {
          if (x + y + z < m) {
            m = x + y + z;
          }
        }
      }
    }
    cout << m << endl;
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int E;
int main() {
  while (cin >> E && E > 0) {
    int m = 500;
    for (int z = 0; z <= cbrt(E); z++) {
      if (z >= m)
        break;
      for (int y = 0; y <= sqrt(E - pow(z, 3)); y++) {
        if (y + z >= m)
          break;
        int x = E - pow(z, 3) - pow(y, 2);
        if (x >= 0) {
          if (x + y + z < m) {
            m = x + y + z;
          }
        }
      }
    }
    cout << m << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, a) repi(i, 0, a)

int e;

int main() {
  while (scanf("%d", &e), e) {
    int ans = 1000000;

    rep(y, sqrt(e) + 1) rep(z, cbrt(e) + 1) if (y * y + z * z * z <= e) ans =
        std::min(ans, (e - y * y - z * z * z) + y + z);

    printf("%d\\n", ans);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, a) repi(i, 0, a)

int e;

int main() {
  while (scanf("%d", &e), e) {
    int ans = 1000001;

    rep(x, e + 1) rep(y, sqrt(e) + 1)
        rep(z, cbrt(e) + 1) if (x + y * y + z * z * z == e) ans =
            std::min(ans, x + y + z);

    printf("%d\\n", ans);
  }

  return 0;
}