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

#include <bits/stdc++.h>
using namespace std;
const int dx[] = {1, 0, 0, -1, 1, -1, -1, 1, 2, 0, -2, 0};
const int dy[] = {0, 1, -1, 0, 1, 1, -1, -1, 0, 2, 0, -2};
const int INF = 1 << 30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i, j, k) for (int i = (j); i < (k); ++i)
#define rep(i, j) reps(i, 0, j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef pair<int, int> Pii;
typedef pair<int, Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
int main() {
  int e;
  while (scanf("%d", &e), e) {
    int ans = INF;
    rep(y, 1001) {
      rep(z, 101) {
        int Y = y * y;
        int Z = z * z * z;
        if (Y + Z > e)
          continue;
        ans = min(ans, e - Y - Z + y + z);
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int dx[] = {1, 0, 0, -1, 1, -1, -1, 1, 2, 0, -2, 0};
const int dy[] = {0, 1, -1, 0, 1, 1, -1, -1, 0, 2, 0, -2};
const int INF = 1 << 30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i, j, k) for (int i = (j); i < (k); ++i)
#define rep(i, j) reps(i, 0, j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef pair<int, int> Pii;
typedef pair<int, Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
int main() {
  int e;
  while (scanf("%d", &e), e) {
    int ans = INF;
    rep(y, 1000) {
      rep(z, 100) {
        int Y = y * y;
        int Z = z * z * z;
        if (Y + Z > e)
          continue;
        int l = 0;
        int r = 1000001;
        while (l != r) {
          int med = (l + r) / 2;
          if (med + Y + Z == e) {
            ans = min(ans, med + y + z);
            break;
          }
          if (med + Y + Z < e) {
            l = med + 1;
          } else {
            r = med;
          }
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int e;
int main() {

  vector<int> ans;
  while (cin >> e, e) {
    int m = 1000000;
    for (int i = 0; i <= e; ++i) {
      if (i * i * i > e)
        break;
      for (int j = 0; j <= e; ++j) {
        if (i * i * i + j * j > e)
          break;
        if (e - i * i * i - j * j >= 0)
          m = min(m, i + j + e - i * i * i - j * j);
      }
    }
    ans.push_back(m);
  }
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int e;
int main() {

  vector<int> ans;
  while (cin >> e, e) {
    int m = 1000000;
    for (int i = 0; i <= e; ++i) {
      if (i * i * i > e)
        break;
      for (int j = 0; j <= e; ++j) {
        if (i * i * i + j * j > e)
          break;
        for (int k = 0; k <= e; ++k) {
          if (i * i * i + j * j + k == e)
            m = min(m, i + j + k);
        }
      }
    }
    ans.push_back(m);
  }
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

void solve() {
  int e;
  while (cin >> e, e) {
    int min_val = 999999999;
    for (int z = 0; z <= 100; ++z) {
      if (e < z * z * z) {
        break;
      }
      for (int y = 0; y <= 1000; ++y) {
        int temp = z * z * z + y * y;
        if (e < temp) {
          break;
        }
        int x = e - temp;
        min_val = min(min_val, x + y + z);
      }
    }
    cout << min_val << endl;
  }
}

int main() {
  solve();
  return (0);
}

Error: TLE

Fixed submission:

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

using namespace std;

void solve() {
  int e;
  while (cin >> e, e) {
    int min_val = 999999999;
    for (int i = 0; i * i * i <= e; ++i) {
      if (i >= min_val) {
        break;
      }
      for (int j = 0; j * j <= e; ++j) {
        if (i * i * i + j * j > e || i + j >= min_val) {
          break;
        }
        for (int k = 0; k <= e; ++k) {
          unsigned long long int temp = i * i * i + j * j + k;
          int val = i + j + k;
          if (temp > e || val >= min_val) {
            break;
          } else if (temp == e) {
            if (min_val > i + j + k) {
              min_val = i + j + k;
            }
          }
        }
      }
    }
    cout << min_val << endl;
  }
}

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

#include <iostream>
using namespace std;

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int e;
  while (cin >> e && e != 0) {
    int ans = e;
    for (int z = 0; z <= e; z++) {
      if (z * z * z > e)
        break;
      if (z >= ans)
        break;
      for (int y = 0; y <= e; y++) {
        if (z + y >= ans)
          break;
        if (z * z * z + y * y > e)
          break;
        for (int x = 0; x <= e; x++) {
          if (x + y + z >= ans)
            break;
          if (x + y * y + z * z * z > e)
            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 <iostream>
using namespace std;
int main() {

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {

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

#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  int e, x, y, z;

  for (;;) {
    cin >> e;
    if (!e)
      break;
    int xm = e + 1;
    int ym = (int)sqrt(e) + 1;
    int zm = (int)cbrt(e) + 1;

    int f, g2, g3, m = 3 * e;
    for (int i = zm; 0 <= i; --i) {
      for (int j = 0; j <= ym; ++j) {
        if (i * i * i + j * j <= e) {
          int k = e - i * i * i - j * j;
          f = i + j + k;
          if (f < m)
            m = f;
        }
      }
    }

    cout << m << endl;
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  int e, x, y, z;

  for (;;) {
    cin >> e;
    if (!e)
      break;
    int xm = e;
    int ym = (int)sqrt(e) + 1;
    int zm = (int)cbrt(e) + 1;

    int f, g, m = 3 * e;
    for (int i = zm; 0 < i; --i)
      for (int j = 0; j < ym; ++j)
        if (i * i * i + j * j < e)
          for (int k = 0; k < xm; ++k) {
            f = k + j + i;
            g = k + j * j + i * i * i;
            if (g > e)
              break;
            if (e == g) {
              f = k + j + i;
              if (f < m)
                m = f;
            }
          }
    cout << m << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#define REP(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;

int E;

int main(void) {
  while (cin >> E, E) {
    int ans = 100000000;
    REP(z, 0, 101) {
      int z3 = z * z * z;
      if (z3 > E)
        break;
      REP(y, 0, 1001) {
        int y2 = y * y;
        int x = E - z3 - y2;
        if (x < 0)
          continue;
        ans = min(ans, x + y + z);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#define REP(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;

int E;

int main(void) {
  while (cin >> E, E) {
    int ans = 100000000;
    REP(z, 0, 100) {
      int z3 = z * z * z;
      if (z3 > E)
        break;
      REP(y, 0, 1000) {
        int y2 = y * y;
        if (z3 + y2 > E)
          break;
        REP(x, 0, 1000000) {
          if (z3 + y2 + x > E)
            break;
          if (z3 + y2 + x == E)
            ans = min(ans, x + y + z);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vi vector<int>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i <= (int)(n); i++)
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int dou(int a) { return a * a; }

int tri(int a) { return a * a * a; }

int main() {

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

    int x, y, z;

    int cb = cbrt(e + 0.00001);

    int m = 1000000;

    REP(i, cb) {
      z = cb - i;
      int huga = sqrt(e - tri(z) + 0.000001);
      REP(j, huga) {
        y = huga - j;
        x = e - tri(z) - dou(y);
        if (m > (x + y + z))
          m = x + y + z;
      }
    }

    cout << m << endl;

    //	cout << z << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vi vector<int>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll int pow(int a, int b) {
  int ans = 1;
  REP(i, b) ans = ans * a;
  return ans;
}

int hoge(int e) {

  int num;

  REP(a, e + 1) {
    REP(b, e + 1) {
      REP(c, e + 1) {
        num = a + b * b + c * c * c;
        //		cout << num << endl;
        if (num > e)
          break;
        if (num == e)
          return (a + b + c);
      }
    }
  }

  return -1;
}

int main() {

  int e;

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

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

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

int main(int argc, char *argv[]) {
  int x, y, z, e, m;
  while (cin >> e, e) {
    m = 1000000;
    for (z = 0; z * z * z <= e; ++z) {
      y = sqrt(e - z * z * z);
      x = e - z * z * z - y * y;
      m = min(m, x + y + z);
    }
    cout << m << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main(int argc, char *argv[]) {
  int x, y, z, e, m, z3, y2;
  while (cin >> e, e) {
    m = 1000000;
    for (int z = 0; z <= 100; ++z) {
      z3 = z * z * z;
      if (z3 > e)
        break;
      for (int y = 0; y <= sqrt(e - z3); ++y) {
        y2 = y * y;
        for (int x = 0; x <= e - (y2 + z3); ++x) {
          if (x + y2 + z3 == e) {
            m = min(m, x + y + z);
            break;
          }
        }
      }
    }
    cout << m << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <complex>
#include <iostream>
#include <map>
#include <math.h>
#include <string>

using namespace std;

int main() {

  int e;

  while (cin >> e, e) {

    int x, y, z;
    int answer = 1000000;
    /*for(int i=0;i<=e;i++){
        for(int j=0;j<=sqrt(e)-i;j++){
            for(int k=0;k<=pow(e,1.0/3.0)-i+pow(j,2.0);k++){
                if(i+pow(j,2.0)+pow(k,3.0)==e&&answer>i+j+k){
                    answer = i+j+k;
                }
            }
        }
    }*/

    for (int k = 0; k * k * k <= e; k++) {
      for (int j = 0; j * j <= e - k * k * k; j++) {
        int i = e - j * j - k * k * k;
        if (answer > i + j + k) {
          answer = i + j + k;
        }
      }
    }

    cout << answer << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <complex>
#include <iostream>
#include <map>
#include <math.h>
#include <string>

using namespace std;

int main() {

  int e;

  while (cin >> e, e) {

    int x, y, z;
    int answer = 1000000;
    /*for(int i=0;i<=e;i++){
        for(int j=0;j<=sqrt(e)-i;j++){
            for(int k=0;k<=pow(e,1.0/3.0)-i+pow(j,2.0);k++){
                if(i+pow(j,2.0)+pow(k,3.0)==e&&answer>i+j+k){
                    answer = i+j+k;
                }
            }
        }
    }*/

    for (int k = 0; k * k * k <= e; k++) {
      for (int j = 0; j * j <= e - k * k * k; j++) {
        int i = e - j * j - k * k * k;
        if (i + pow(j, 2.0) + pow(k, 3.0) == e && answer > i + j + k) {
          answer = i + j + k;
        }
      }
    }

    cout << answer << 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 m = 1 << 30;
    for (int y = 0; y <= 1000; y++) {
      for (int z = 0; z <= 100; z++) {
        int x = e - y * y - z * z * z;
        if (x >= 0)
          m = min(m, x + y + z);
      }
    }
    cout << m << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int e;
  while (cin >> e && e) {
    int m = 1 << 30, tmp;
    for (int x = 0; x <= 1000000 && x <= e; x++) {
      for (int y = 0; y <= 1000 && (x + y * y) <= e; y++) {
        for (int z = 0; z <= 100 && (x + y * y + z * z * z) <= e; z++) {
          if ((x + y * y + z * z * z) == e)
            m = min(m, x + y + z);
        }
      }
    }
    cout << m << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int solve(int n) {
  int e = 1e6;
  for (int i = 0; i * i * i <= n; ++i) {
    for (int k = 0; k * k <= n - i * i * i; ++k) {
      e = min(e, n - i * i * i - k * k + i + k);
    }
  }
  return e;
}

int main() {
  int n;
  while (true) {
    cin >> n;
    if (n == 0) {
      break;
    }
    cout << solve(n) << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

bool check(int a, int b, int c, int n) {
  if (a + b * b + c * c * c == n) {
    return true;
  }
  return false;
}

int solve(int n) {
  int a, b, c;
  a = 0;
  b = 0;
  c = 0;
  if (check(a, b, c, n)) {
    return a + b + c;
  }
  for (int i = 0; i < 1000000; ++i) {
    if (check(a, b, c + 1, n)) {
      return a + b + c;
    }
    if (check(a, b + 1, c, n)) {
      return a + b + c;
    }
    if (check(a + 1, b, c, n)) {
      return a + b + c;
    }
    if (check(a, b + 1, c + 1, n)) {
      return a + b + c;
    }
    if (check(a + 1, b, c + 1, n)) {
      return a + b + c;
    }
    if (check(a + 1, b + 1, c, n)) {
      return a + b + c;
    }
    if (check(++a, ++b, ++c, n)) {
      return a + b + c;
    }
  }
}

int main() {
  int n;
  while (true) {
    cin >> n;
    if (n == 0) {
      break;
    }
    cout << solve(n) << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  while (1) { // start

    int e;
    int ans = 10000000;
    cin >> e;

    if (e == 0)
      break;

    int x;
    for (int y = 0; y <= 1000; y++) {
      for (int z = 0; z <= 100; z++) {
        if (y * y + z * z > e)
          break;
        x = e - y * y - z * z * z;
        if (x + y * y + z * z * z > e)
          break;
        if (x >= 0 and x + y * y + z * z * z == e) {
          ans = min(ans, x + y + z);
          // cout << "ans = " << ans << endl;
        }
      }
    }

    cout << ans << endl;

  } // end
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  while (1) { // start

    int e;
    int ans = 100000000;
    // cin >> e;
    scanf("%d", &e);

    if (e == 0)
      break;

    int y_lim = 1000;
    if (e * e < 1000)
      y_lim = e * e;
    int z_lim = 100;
    if (e * e * e < 100)
      z_lim = e * e * e;

    for (int x = 0; x < e; x++) {
      for (int y = 0; y <= y_lim; y++) {
        if (x + y * y > e)
          break;
        for (int z = 0; z <= z_lim; z++) {
          if (x + y * y + z * z * z > e)
            break;
          else if (x + y * y + z * z * z == e) {
            ans = min(ans, x + y + z);
          }
        }
      }
    }

    // cout << ans << endl;
    printf("%d\\n", ans);

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

#include <algorithm>
#include <iostream>
using namespace std;
#define INF 9999999

int main() {
  int e;

  while (cin >> e, e) {
    // x+y^2+z^3=e
    int ans = INF;

    for (int z = 0; z * z * z <= e; z++) {
      for (int y = 0; (y * y) + (z * z * z) <= e; y++) {
        ans = min(ans, e - y * y - z * z * z + y + z);
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
#define INF 9999999

int main() {
  int e;

  while (cin >> e, e) {
    // x+y^2+z^3=e
    int ans = INF;

    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)
            ans = min(ans, x + y + z);
        }
      }
    }

    cout << ans << endl;
  }

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

#include <iostream>
using namespace std;
int E, Count;
int solve(int E);

int solve(int E) {
  int x, y, z;
  int min = E;
  for (z = 0; z * z * z <= E; z++) {
    for (y = 0; y * y <= E - z * z * z; y++) {
      x = E - z * z * z - y * y;
      Count++;
      if (x >= 0 && x + y + z < min) {
        min = x + y + z;
      }
    }
  }
  return min;
}
int main() {
  while (cin >> E && E > 0) {
    //  cout << "min  : " << solve(E) << endl
    // << "count: " << Count << endl;
    cout << solve(E) << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;
int E;
int solve(int E);

int solve(int E) {
  int x, y, z3, z;
  int min = E;
  for (x = 0; x <= E; x++) {
    for (y = 0; y * y <= E - x; y++) {
      z3 = E - x - y * y;
      z = round(pow(z3, 1.0 / 3.0));
      if (x + y * y + z * z * z == E && x + y + z < min) {
        min = x + y + z;
      }
    }
  }
  return min;
}
int main() {
  while (cin >> E && E > 0) {
    cout << solve(E) << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int e;
  while (cin >> e, e) {
    int x, y, z;
    int ans = INT_MAX;
    for (z = 0; z * z * z <= e; z++) {
      y = sqrt(e - pow(z, 3));
      x = e - pow(z, 3) - pow(y, 2);
      ans = min(ans, x + y + z);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int e;
  while (cin >> e, e) {
    int x, y, z;
    int ans = INT_MAX;
    for (z = 0; z <= pow(e, 1.0 / 3.0); z++) {
      for (y = 0; y <= sqrt(e); y++) {
        if (pow(z, 3) + pow(y, 2) > e)
          break;
        ans = min(ans, (int)(z + y + (e - pow(y, 2) - pow(z, 3))));
      }
    }
    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 < (int)(n); i++)
#define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;

template <typename T> void show_all(T t) {
  rep(i, t.size()) {
    rep(j, t[0].size()) { cout << t[i][j]; }
    cout << endl;
  }
}

int main() {
  int e;
  while (1) {
    cin >> e;
    if (!e)
      break;

    // greedy(O(3*N)?): WA
    // int i;
    // int x, y, z;
    // for (i=0; pow(i, 3) <= e; i++) {}
    // z = i-1;
    // e -= pow(z, 3);
    //
    // for (i=0; pow(i, 2) <= e; i++) {}
    // y = i-1;
    // e -= pow(y, 2);
    //
    // x = e;
    // cout << x+y+z << endl;
    //

    // O(N^2): TLE
    // int ans = 10000000 + 7;
    // for (int z=0; pow(z,3)<=e; z++) {
    //   for (int y=0; pow(z,3)+pow(y,2)<=e; y++) {
    //     int x = e - (pow(z,3)+pow(y,2));
    //     if (x + pow(y,2) + pow(z,3) != e) continue;
    //     ans = min(ans, x+y+z);
    //   }
    // }

    int ans = 10000000 + 7;
    for (int z = 0; pow(z, 3) <= e; z++) {
      int y = sqrt(e - pow(z, 3));
      int x = e - pow(z, 3) - pow(y, 2);
      if (x + pow(y, 2) + pow(z, 3) != e)
        continue;
      ans = min(ans, x + y + z);
    }

    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;

template <typename T> void show_all(T t) {
  rep(i, t.size()) {
    rep(j, t[0].size()) { cout << t[i][j]; }
    cout << endl;
  }
}

int main() {
  int e;
  while (1) {
    cin >> e;
    if (!e)
      break;
    // int i;
    // int x, y, z;
    // for (i=0; pow(i, 3) <= e; i++) {}
    // z = i-1;
    // e -= pow(z, 3);
    //
    // for (i=0; pow(i, 2) <= e; i++) {}
    // y = i-1;
    // e -= pow(y, 2);
    //
    // x = e;
    //
    // cout << x << ' ' << y << ' ' << z << ' ' << x + pow(y,2) + pow(z, 3) << '
    // ' << x + y + z << endl;

    int ans = 10000000 + 7;

    for (int z = 0; pow(z, 3) <= e; z++) {
      for (int y = 0; pow(z, 3) + pow(y, 2) <= e; y++) {
        int x = e - (pow(z, 3) + pow(y, 2));
        if (x + pow(y, 2) + pow(z, 3) != e)
          continue;
        ans = min(ans, x + y + z);
      }
    }

    cout << ans << endl;
  }
}