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

#include <iostream>
using namespace std;

int solve(int E) {
  int ans = 1000000;
  int x;
  for (int y = 0; y * y <= E; ++y) {
    for (int z = 0; z * z * z <= E; ++z) {
      x = E - y * y - z * z * z;
      if (x >= 0)
        ans = min(ans, x + y + z);
    }
  }
  return ans;
}

int main() {
  int E;
  while (cin >> E && E > 0) {
    cout << solve(E) << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int solve(int E) {
  int ans = 1000000;
  for (int y = 0; y <= E; ++y) {
    for (int z = 0; z <= E; ++z) {
      int x = E - y * y - z * z;
      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 <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int e, m, a;

  while (1) {
    cin >> e;
    m = e;
    if (e == 0) {
      return 0;
    }
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m - i; j++) {
        a = e - i * (i - 1) - j * (j - 1) * (j + 1);
        if ((a >= i + j) && (m > a) && (a >= 0)) {
          m = e - i * (i - 1) - j * (j - 1) * (j + 1);
        }
        if (a < 0) {
          break;
        }
      }
    }
    cout << m << "\\n";
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int e, m, a;

  while (1) {
    cin >> e;
    m = e;
    if (e == 0) {
      return 0;
    }
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m - i; j++) {
        a = e - i * (i - 1) - j * (j - 1) * (j + 1);
        if ((a >= i + j) && (m > a) && (a >= 0)) {
          m = e - i * (i - 1) - j * (j - 1) * (j + 1);
        }
      }
    }
    cout << m << "\\n";
  }

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

#include <iostream>
using namespace std;

int main() {
  int m = 1000000, e;

  while (1) {
    cin >> e;
    m = 1000000;
    if (e == 0)
      break;
    for (int z = 0; z * z * z <= e; z++) {
      for (int y = 0; y * y <= (e - z * z * z); y++) {
        int x = e - y * y - z * z * z;
        if (e == x + y * y + z * z * z)
          m = min(m, (x + y + z));
      }
    }
    cout << m << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

const int MAX = 1000000;

int main() {
  int m, x, y, z, e;

  while (1) {
    m = MAX;
    cin >> e;
    if (e == 0)
      break;

    for (x = 0; x <= sqrt(MAX / 100); x++) {
      for (y = 0; y <= sqrt(MAX / 10); y++) {
        for (z = 0; z <= sqrt(MAX); z++) {
          if (e == (x + y * y + z * z * z)) {
            m = min(m, (x + y + z));
            break;
          }
        }
      }
    }
    cout << m << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>

using namespace std;

int pw(int n, int p) {
  if (n == 0)
    return 0;
  if (p == 0)
    return 1;
  if (p == 1)
    return n;
  return n * pw(n, p - 1);
}

int computeM(int e) {

  int ret = e;

  // zが最も自由度の小さい数なので、zから決定していく。

  for (int y = 0; y <= sqrt(e); y++) {
    for (int z = 0; z <= sqrt(e); z++) {
      int temp = pw(y, 2) + pw(z, 3);
      int x = e - temp;
      if (x < 0)
        x = 0;
      if (x + temp == e)
        ret = min(x + y + z, ret);
    }
  }

  return ret;
}

int main(void) {
  int e, m;

  while (1) {
    cin >> e;
    if (e == 0)
      break;
    m = computeM(e);
    cout << m << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int pw(int n, int p) {
  if (n == 0)
    return 0;
  if (p == 0)
    return 1;
  if (p == 1)
    return n;
  return n * pw(n, p - 1);
}

int computeM(int e) {

  int temp, ret = e;

  for (int x = 0; x <= e; x++) {
    for (int y = 0; y <= e; y++) {
      for (int z = 0; z <= e; z++) {
        for (int i = 0; i <= e; i++) {
          for (int j = 0; j <= e; j++) {
            for (int k = 0; k < e; k++) {
              temp = pw(x, i) + pw(y, j) + pw(z, k);
              if (temp == e)
                ret = min(x + y + z, ret);
            }
          }
        }
      }
    }
  }

  return ret;
}

int main(void) {
  int e, m;

  while (1) {
    cin >> e;
    if (e == 0)
      break;
    m = computeM(e);
    cout << m << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int max(int, int);

int main(void) {
  int min, x = 0;
  int e;
  cin >> e;

  while (e != 0) {
    min = e;
    for (int z = 0; z * z * z <= e; z++) {
      for (int y = 0; y * y <= e - z * z * z; y++) {
        x = e - z * z * z - y * y;
        if (x + y + z < min)
          min = x + y + z;
      }
    }

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


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

int max(int, int);

int main(void) {
  int e, min, zzz, ez, ezy, x = 0;
  cin >> e;

  while (e != 0) {
    min = e;
    zzz = pow(e, 1.0 / 3.0);
    for (int z = 0; z <= zzz; z++) {
      ez = e - z * z * z;
      for (int y = 0; y * y <= ez; y++) {
        x = ez - y * y;
        if (x + y + z < min)
          min = x + y + z;
        if (y >= min)
          y = e;
      }
      if (z >= min)
        z = e;
    }

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

#include <cmath>
#include <iostream>

int main() {
  int e;
  while (std::cin >> e, e > 0) {
    int m = e; // ツ可シツづ個値
    const int z_max =
        static_cast<int>(pow(static_cast<double>(e), 1. / 3.)) + 1;
    for (int z = 0; z <= z_max; ++z) {
      const int y_max = static_cast<int>(sqrt(static_cast<double>(e))) + 1;
      for (int y = 0; y < y_max; ++y) {
        const int x = e - y * y - z * z * z;
        if (x < 0) {
          break;
        }
        const int m_ = x + y + z;
        if (m_ < m) {
          m = m_;
        }
      }
    }
    std::cout << m << std::endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

int main() {
  int e;
  while (std::cin >> e, e > 0) {
    int m = e; // ツ可シツづ個値
    for (int y = 0; y < e; ++y) {
      for (int z = 0; z < e; ++z) {
        const int x = e - y * y - z * z * z;
        if (x < 0) {
          break;
        }
        const int m_ = x + y + z;
        if (m_ < m) {
          m = m_;
        }
      }
    }
    std::cout << m << std::endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  int E, X, tempmin;
  int min;

  while (true) {
    cin >> E;
    if (E == 0) {
      break;
    }
    min = 1000000;
    for (int Z = 0; Z * Z * Z <= E; Z++) {
      for (int Y = 0; Y * Y <= (E - Z * Z * Z); Y++) {
        X = E - Y * Y - Z * Z * Z;
        tempmin = X + Y + Z;
        // cout << X << " " << Y << " " << Z << endl;
        // cout << tempmin << endl;
        if ((tempmin < min) && (X + Y * Y + Z * Z * Z == E)) {
          min = tempmin;
        }
      }
    }
    cout << min << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  int E, X, tempmin;
  int min;

  while (true) {
    cin >> E;
    if (E == 0) {
      break;
    }
    min = 1000000;
    for (int Z = 0; Z * Z * Z <= E; Z++) {
      for (int Y = 0; Y * Y <= (E - Z * Z * Z); Y++) {
        X = E - Y * Y - Z * Z * Z;
        tempmin = X + Y + Z;
        cout << X << " " << Y << " " << Z << endl;
        // cout << tempmin << endl;
        if ((tempmin < min) && (X + Y * Y + Z * Z * Z == E)) {
          min = tempmin;
        }
      }
    }
    cout << min << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main(void) {
  for (;;) {
    int e;
    cin >> e;
    int m = 1 << 26;
    if (e == 0) {
      return 0;
    }
    for (int z = 0; z * z * z <= e; z++) {
      for (int y = 0; y * y + z * z * z <= e; y++) {
        int x = e - y * y - z * z * z;
        if (x + y + z < m) {
          m = x + y + z;
        }
      }
    }
    cout << m << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  for (;;) {
    int e;
    cin >> e;
    int m = 1 << 26;
    if (e == 0) {
      return 0;
    }
    for (int z = 0; z * z * z <= e; z++) {
      for (int y = 0; y * y + z * z * z <= e; y++) {
        for (int x = 0; x + y * y + z * z * z <= e; x++) {
          if (x + y * y + z * z * z == e && x + y + z < m) {
            m = x + y + z;
          }
        }
      }
    }
    cout << m << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;
int solve(int E) {
  int ans = 3000000;
  int x;
  for (int y = 0; y <= 1000; ++y)
    for (int z = 0; z <= 100; ++z) {
      x = E - y * y - z * z * z;
      if ((x + y + z < ans) && (x >= 0))
        ans = x + y + z;
    }
  return ans;
}
int main() {
  int E;
  while (cin >> E && E > 0)
    cout << solve(E) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int solve(int E) {
  int ans = 3 * E;
  for (int x = 0; x <= E; ++x)
    for (int y = 0; y <= (int)round(pow(E - x, 1.0 / 2)); ++y)
      for (int z = 0; z <= (int)round(pow(E - x - y * y, 1.0 / 3)); ++z) {
        if (x + y * y + z * z * z == E) {
          if (x + y + z < ans)
            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: Runtime Error

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

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

  vector<int> v(1000001, 1 << 30);
  const int n = 400;
  for (int x = 0; x < n; x++) {
    for (int y = 0; y < n; y++) {
      for (int z = 0; z < n; z++) {
        if (x + y * y + z * z * z > 1000001)
          continue;
        v[x + y * y + z * z * z] = min(v[x + y * y + z * z * z], x + y + z);
      }
    }
  }

  while (1) {
    int e;
    cin >> e;
    if (e == 0)
      break;

    cout << v[e] << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

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

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

  while (1) {
    int e;
    cin >> e;
    if (e == 0)
      break;
    vector<int> v;
    const int n = 110;
    for (int x = 0; x < n; x++) {
      for (int y = 0; y < n; y++) {
        for (int z = 0; z < n; z++) {
          if (x + y * y + z * z * z == e) {
            v.push_back(x + y + z);
          }
        }
      }
    }
    sort(v.begin(), v.end());
    cout << v[0] << endl;
  }

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

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

static const int tx[] = {0, 1, 0, -1};
static const int ty[] = {-1, 0, 1, 0};

static const double EPS = 1e-8;

int main() {
  int e;
  while (~scanf("%d", &e)) {
    if (e == 0)
      break;
    int res = INF;

    for (int y = 0; y * y <= e; y++) {
      for (int z = 0; y * y + z * z * z <= e; z++) {
        res = min(res, y + z + (e - y * y - z * z * z));
      }
    }
    printf("%d\\n", res);
  }
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

static const int tx[] = {0, 1, 0, -1};
static const int ty[] = {-1, 0, 1, 0};

static const double EPS = 1e-8;

int main() {
  int e;
  while (~scanf("%d", &e)) {

    int res = INF;
    for (int z = 0; e - z * z * z >= 0; z++) {
      for (int x = 0; x <= e - z * z * z; x++) {
        int tmp = e - z * z * z - x;
        int y = (int)sqrt((double)tmp + EPS);
        if (tmp == y * y) {
          res = min(res, x + y + z);
        }
      }
    }

    printf("%d\\n", res);
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int ene;
  while (cin >> ene && ene > 0) {
    int min = 1000000;
    for (int z = 0; z <= 100; z++) {
      int xy = ene - z * z * z;
      if (xy >= 0)
        for (int y = 0; y <= 10000; y++) {
          int x = xy - y * y;
          if (x >= 0)
            if (x + y + z < min)
              min = x + y + z;
        }
    }
    cout << min << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int ene;
  while (cin >> ene && ene > 0) {
    int min = 1000000;
    for (int z = 0; z <= 100; z++) {
      int xy = ene - z * z * z;
      if (xy >= 0)
        for (int y = 0; y <= xy; y++) {
          int x = xy - y * y;
          if (x >= 0)
            if (x + y + z < min)
              min = x + y + z;
        }
    }
    cout << min << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int i, j;
  int a[102], b[1002], m, n;
  for (i = 0; i < 102; i++)
    a[i] = (int)pow(i, 3);
  for (i = 0; i < 1002; i++)
    b[i] = (int)pow(i, 2);
  while (cin >> n && n) {
    m = 2000000000;
    for (i = 0; a[i] <= n; i++)
      for (j = 0; b[j] <= n - a[i]; j++)
        m = min(m, n - a[i] - b[j] + i + j);
    cout << m << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int i, j;
  int m, n;
  while (cin >> n && n) {
    m = 2000000000;
    for (i = 0; (int)pow(i, 3) <= n; i++)
      for (j = 0; (int)pow(j, 2) <= n - (int)pow(i, 3); j++)
        m = min(m, n - (int)pow(i, 3) - (int)pow(j, 2) + i + j);
    cout << m << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

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

const int INF = 10000000;
using namespace std;
typedef long long ll;
const int MAX = 10000;

/** Problem2012 : Space Coconut Grab **/
int main() {
  int e;
  int m = INF;

  while (cin >> e, e != 0) {
    m = INF;
    REP(i, 0, 1000) {
      REP(j, 0, 1000) {
        if (e - i * i - j * j * j >= 0) {
          int t = e - i * i - j * j * j + i + j;
          if (t < m)
            m = t;
        }
      }
    }
    cout << m << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

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

const int INF = 10000000;
using namespace std;
typedef long long ll;
const int MAX = 10000;

/** Problem2012 : Space Coconut Grab **/
int main() {
  int e;
  int m = INF;

  while (cin >> e, e != 0) {
    m = INF;
    rep(i, 150) {
      rep(j, 150) {
        rep(k, 150) {
          if (i + j * j + k * k * k == e) {
            if (m > i + j + k) {
              m = i + j + k;
            }
          }
        }
      }
    }
    cout << m << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

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

    cin >> e;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int e;
  while (true) {
    cin >> e;
    if (!e) {
      break;
    }
    int MIN = 2 << 10;
    for (int i = 0; i * i * i <= e; i++) {
      for (int j = 0; i * i * i + j * j <= e; j++) {
        for (int k = 0; i * i * i + j * j + k <= e; k++) {
          if (e != i * i * i + j * j + k) {
            continue;
          } else if (e < i * i * i + j * j + k) {
            break;
          }
          MIN = min(i + j + k, MIN);
        }
      }
    }
    cout << MIN << endl;
  }

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

#include <iostream>

using namespace std;

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

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> two, three;
  for (int i = 0; i * i <= 1000000; i++) {
    two.push_back(i * i);
  }
  for (int i = 0; i * i * i <= 1000000; i++) {
    three.push_back(i * i * i);
  }

  int e;
  while (cin >> e, e) {
    int tw, th;
    int min = e;

    for (int i = 0; three[i] <= e; i++) {
      for (int j = 0; three[i] + two[j] <= e; j++) {
        if (three[i] + two[j] <= e) {
          if (i + j + (e - three[i] - two[j]) < min)
            min = i + j + (e - three[i] - two[j]);
        }
      }
    }
    cout << min << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, j, k) for (int i = (int)j; i < (int)k; i++)
#define itrep(x) for (auto it = (x).begin(); it != (x).end(); it++)
#define Sort(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int, int> P;
int D = 1;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

using namespace std;

int main() {
  while (1) {
    int e;
    int ans = 1e9 + 7;
    cin >> e;
    if (e == 0)
      break;

    rep(i, 0, 1000) {
      rep(j, 0, 1000) {
        int k = e - i * i - j * j * j;
        if (k < 0)
          continue;
        ans = min(ans, i + j + k);
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, j, k) for (int i = (int)j; i < (int)k; i++)
#define itrep(x) for (auto it = (x).begin(); it != (x).end(); it++)
#define Sort(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int, int> P;
int D = 1;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

using namespace std;

int main() {
  while (1) {
    int e;
    int ans = 1e9 + 7;
    cin >> e;
    if (e == 0)
      break;

    for (int i = 0; i <= e; i++) {
      for (int j = 0; i + j * j <= e; j++) {
        for (int k = 0; i + j * j + k * k * k <= e; k++) {
          if (i + j * j + k * k * k == e)
            ans = min(ans, i + j + k);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  while (n != 0) {
    int a;
    a = 1e9;
    for (int i = 0; i * i * i <= n; i++) {
      for (int j = 0; j * j + i * i * i <= n; j++) {
        int t = (n - i * i * i - j * j);
        if (t >= 0)
          a = min(i + j + t, a);
      }
    }
    cout << a << endl;
    cin >> n;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  while (n != 0) {
    int a;
    a = 1e9;
    for (int i = 0; i < pow(n, 0.34); i++) {
      for (int j = 0; j <= pow(n, 0.5); j++) {
        int t = (n - i * i * i - j * j);
        if (t >= 0)
          a = min(i + j + t, a);
      }
    }
    cout << a << endl;
    cin >> n;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int e;
  while (cin >> e, e) {
    int ans = 1000000;
    for (int z = 0; z * z * z <= e; ++z) {
      for (int y = 0; y * y + z * z * z <= e; ++y) {
        int x = e - y * y - z * z * z;
        ans = min(ans, x + y + z);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int e;
  while (cin >> e, e) {
    int ans = 1000000;
    for (int z = 0; z <= e; ++z) {
      for (int y = 0; y * y + z * z * z <= e; ++y) {
        int x = e - y * y - z * z * z;
        ans = min(ans, x + y + z);
      }
    }
    cout << ans << endl;
  }
  return 0;
}