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

#include <iostream>
#include <math.h>
using namespace std;
int solve(int E) {
  int ans = E;
  for (int z = 0; z * z * z <= E; ++z) {
    for (int y = 0; y * y <= E; ++y) {
      int 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;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;
int solve(int E) {
  int ans = E;
  for (int z = 0; z * z * z <= E; ++z) {
    for (int y = 0; y * y <= E; ++y) {
      for (int x = 0; x < E; ++x)
        if (x + y * y + z * z * z == E && 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: Time Limit Exceeded

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

using namespace std;

int INF = 10000000;

int cast(int e) {

  int Min = INF;

  for (int i = 0; i * i * i <= e; i++) {
    for (int j = 0; j * j <= e - i * i * i; j++) {
      int k = e - i * i * i - j * j;
      if (k >= 0) {
        Min = min(i + j + k, Min);
      } else {
        break;
      }
    }
  }

  return Min;
}

int main() {

  while (1) {
    int e;

    cin >> e;

    if (!e)
      break;

    cout << cast(e) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int INF = 10000000;

int cast(int e) {

  int Min = INF;

  for (int i = 0; pow(i, 3) <= e; i++) {
    for (int j = 0; pow(j, 2) <= e - pow(i, 3); j++) {
      int k = e - pow(i, 3) - pow(j, 2);
      if (k >= 0) {
        Min = min(i + j + k, Min);
      } else {
        break;
      }
    }
  }

  return Min;
}

int main() {

  while (1) {
    int e;

    cin >> e;

    if (!e)
      break;

    cout << cast(e) << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define INF 999999999
#define mod 1000000007

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define REP(i, a, b) for (int i = (a); i < int(b); i++)
#define all(x) (x).begin(), x.end()
#define pb push_back
#define MOD(x) (x % (mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;

/*---------------------------------------------------*/

int main() {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int mini = INF;
    for (int y = 0; y * y <= n; y++) {
      for (int z = 0; z * z * z <= n; z++) {
        int x = n - y * y - z * z * z;
        if (x < 0)
          continue;
        // cout<<x<<" "<<y<<" "<<z<<endl;
        mini = min(mini, x + y + z);
      }
    }
    cout << mini << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define INF 999999999
#define mod 1000000007

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define REP(i, a, b) for (int i = (a); i < int(b); i++)
#define all(x) (x).begin(), x.end()
#define pb push_back
#define MOD(x) (x % (mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;

/*---------------------------------------------------*/

int main() {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int mini = INF;
    rep(y, sqrt(n)) {
      rep(z, sqrt(n)) {
        int x = n - pow(y, 2) - pow(z, 3);
        if (x < 0)
          continue;
        // cout<<x<<" "<<y<<" "<<z<<endl;
        mini = min(mini, x + y + z);
      }
    }
    cout << mini << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define REP(i, m) for (long long i = 0; i < m; i++)
#define FOR(i, n, m) for (long long i = n; i < m; i++)
#define INF 1000000000
#define INFL 10000000000000000LL
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      return 0;
    ll ans = INF;
    REP(i, (int)pow(n, 0.335) + 1) {
      if (n < i * i * i)
        break;
      int j = (int)pow(n - i * i * i, 0.5);
      if (ans > i + j + (n - i * i * i - j * j)) {
        ans = i + j + (n - i * i * i - j * j);
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define REP(i, m) for (long long i = 0; i < m; i++)
#define FOR(i, n, m) for (long long i = n; i < m; i++)
#define INF 1000000000
#define INFL 10000000000000000LL
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      return 0;
    ll ans = INF;
    REP(i, (int)pow(n, 0.335) + 1) {
      REP(j, (int)pow((n - i * i * i), 0.5) + 1) {
        int k = n - (i * i * i) - (j * j);
        if (k >= 0 && i + j + k < ans)
          ans = i + j + k;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#if 0

#endif

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

int mycount = 0; // ambigous??¨???????????????????????????
int solve(int E) {
  // ?????´????±???????
  int ans = 1000000; // ?????§???
  for (int z = 0; z * z * z <= E; ++z)
    for (int y = 0; y * y <= E; ++y) {
      int x = E - z * z * z - y * y;
      ++mycount;
      if (x >= 0 && 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;
}

Error: TLE

Fixed submission:

#if 0

#endif

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

int mycount = 0; // ambigous??¨???????????????????????????
int solve(int E) {
  // ?????´????±???????
  int ans = 1000000; // ?????§???
  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));
      ++mycount;
      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: Time Limit Exceeded

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

const int INF = (int)1e9;

int solve(int E) {
  int res = INF;
  for (int y = 0; y * y <= E; y++) {
    for (int z = 0; y * y + z * z * z <= E; z++) {
      if (res > y + z + E - y * y - z * z * z) {
        res = y + z + E - y * y - z * z * z;
      }
    }
  }
  return res;
}

int main() {
  for (int E; cin >> E, E;) {
    cout << solve(E) << endl;
  }
}

Error: TLE

Fixed submission:

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

const int INF = (int)1e9;

typedef long long lli;

int solve(int E) {
  int res = INF;
  for (lli x = 0; x < res && x <= E; x++) {
    for (lli y = 0; x + y < res && (x + y * y <= E); y++) {
      for (lli z = 0; x + y + z < res && (x + y * y + z * z * z <= E); z++) {
        if (x + y * y + z * z * z == E) {
          res = x + y + z;
        }
      }
    }
  }
  return res;
}

int main() {
  for (int E; cin >> E, E;) {
    cout << solve(E) << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

// b
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i, b, n) for (int i = b; i < n; i++)
#define REPR(i, b, n) for (int i = n - 1; i >= b; i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n >> b) & 1)
#define PB push_back
#define MP make_pair

using namespace std;

static const double PI = acos(-1.0);
static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> pii;

int main() {

  ll e;

  while (cin >> e, e) {

    ll mn = e;

    for (ll y = 0; e - y * y >= 0; ++y) {
      for (ll z = 0; e - z * z * z >= 0; ++z) {

        if (e - y * y - z * z * z >= 0) {
          mn = min(mn, e - y * y - z * z * z + y + z);
        }
      }
    }

    cout << mn << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

// b
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i, b, n) for (int i = b; i < n; i++)
#define REPR(i, b, n) for (int i = n - 1; i >= b; i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n >> b) & 1)
#define PB push_back
#define MP make_pair

using namespace std;

static const double PI = acos(-1.0);
static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> pii;

int main() {

  ll e;

  while (cin >> e, e) {

    ll mn = e;

    for (ll y = 0; y < e; ++y) {
      for (ll z = 0; z < e; ++z) {

        if (e - y * y - z * z * z >= 0) {
          mn = min(mn, e - y * y - z * z * z + y + z);
        }
      }
    }

    cout << mn << endl;
  }

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

#include <bits/stdc++.h>

using namespace std;

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

    int tmpx, tmpy, tmpz, tmpe;
    tmpe = e;
    for (tmpz = 0; pow(tmpz, 3) <= tmpe; tmpz++) {
    }
    tmpz--;
    tmpe = tmpe - pow(tmpz, 3);
    if (tmpe == 0) {
      tmpy = 0;
      tmpx = 0;
    } else {
      for (tmpy = 0; pow(tmpy, 2) <= tmpe; tmpy++) {
      }
      tmpy--;
      tmpe = tmpe - pow(tmpy, 2);
      if (tmpe == 0) {
        tmpx = 0;
      } else {
        tmpx = tmpe;
      }
    }
    int tmpm = tmpx + tmpy + tmpz;
    // cout << tmpz << " ! " << endl;

    int tmp;
    for (int z = 0; z <= tmpz + 1; z++) {
      for (int y = tmpy; y <= min(tmpm - z, int(pow(e - pow(z, 3), 1.0 / 2.0)));
           y++) {
        int x = e - pow(y, 2) - pow(z, 3);
        tmp = x + y + z;
        if (tmp < tmpm) {
          tmpm = tmp;
        }
      }
    }

    cout << tmpm << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

    int tmpx, tmpy, tmpz, tmpe;
    tmpe = e;
    tmpz = pow(e, 1.0 / 3.0);
    tmpe = tmpe - pow(tmpz, 3);
    if (tmpe == 0) {
      tmpy = 0;
      tmpx = 0;
    } else {
      tmpy = pow(tmpe, 1.0 / 2.0);
      tmpe = tmpe - pow(tmpy, 2);
      if (tmpe == 0) {
        tmpx = 0;
      } else {
        tmpx = tmpe;
      }
    }
    int tmpm = tmpx + tmpy + tmpz;

    int tmp;
    for (int z = 0; z <= tmpz; z++) {
      for (int y = 0; y <= min(tmpm - z, int(pow(e - pow(z, 3), 1.0 / 2.0)));
           y++) {
        int x = e - pow(y, 2) - pow(z, 3);
        tmp = x + y + z;
        if (tmp < tmpm) {
          tmpm = tmp;
        }
      }
    }

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

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

int getMinM(int e) {
  int mini = INT_MAX;
  for (int y = 0; y * y <= e; y++) {
    for (int z = 0; z * z * z <= e; z++) {
      int x = e - (y * y + z * z * z);
      if (e == x + y * y + z * z * z && x >= 0)
        mini = min(mini, x + y + z);
    }
  }
  return mini;
}

int main() {
  while (1) {
    int e;
    cin >> e;
    if (e == 0)
      break;
    int mini = INT_MAX;
    cout << getMinM(e) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int getMinM(int e) {
  int mini = INT_MAX;
  for (int y = 0; y * y <= e; y++) {
    for (int z = 0; z * z * z < e; z++) {
      int x = e - (pow(y, 2) + pow(z, 3));
      if (x >= 0)
        mini = min(mini, x + y + z);
    }
  }
  return mini;
}

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

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int e;
int main() {
  while (cin >> e, e) {
    int ans = 10000000;
    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 (ans > x + y + z) {
          ans = x + y + z;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int e;
int main() {
  while (cin >> e, e) {
    int ans = 10000000;
    int m;
    bool flag = true;
    for (int i = 0; i <= 1000000 && flag; i++) {
      if (i >= e + 1) {
        break;
      }
      for (int j = 0; j <= 1000000 && flag; j++) {
        if (i + j >= e + 1 || i + j * j >= e + 1) {
          break;
        }
        for (int k = 0; k <= 1000000 && flag; k++) {
          if (i + j * j + k >= e + 1 || i + j * j + k * k >= e + 1 ||
              i + j * j + k * k * k >= e + 1) {
            break;
          }
          if (i + j * j + k * k * k == e) {
            m = i + j + k;
            ans = min(ans, m);
          }
        }
      }
    }
    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 (scanf("%d", &e), e) {
    int m = 10000000;
    for (int y = 0; y <= 1000; y++) {
      for (int z = 0; z <= 1000; z++) {
        int x = e + y - y * y + z - z * z * z;
        if (x >= 0 && e >= y * y + z * z * z)
          m = min(x, m);
      }
    }
    cout << m << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int e;
  while (scanf("%d", &e), e) {
    int m = 10000000;
    for (int y = 0; y <= 10000; y++) {
      for (int z = 0; z <= 1000; z++) {
        int x = e + y - y * y + z - z * z * z;
        if (x >= 0 && e >= y * y + z * z * z)
          m = min(x, m);
      }
    }
    printf("%d", &m);
  }
}
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 x = 0, m = 81671422;
    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;
        m = min(m, x + y + z);
      }
    }
    cout << m << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int e;
  while (cin >> e, e) {
    int m = 81671422;
    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)
            break;
          else 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 main() {
  while (true) {
    int e;
    cin >> e;
    if (e == 0) {
      break;
    }
    int result = 1 << 30;
    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 (x + y + z < result) {
          result = x + y + z;
        }
      }
    }
    cout << result << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  while (true) {
    int e;
    cin >> e;
    if (e == 0) {
      break;
    }
    int minM = e;
    for (int z = 0; pow(z, 3) <= e; z++) {
      for (int y = 0; pow(y, 2) <= e - pow(z, 3); y++) {
        int x = e - pow(y, 2) - pow(z, 3);
        if (x + y + z < minM) {
          minM = x + y + z;
        }
      }
    }
    cout << minM << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

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

int main() {
  int e, ans;
  while (1) {
    cin >> e;
    if (!e)
      break;
    ans = (1e9);
    for (int z = 0; z * z * z <= e; z++) {
      int Z = z * z * z;
      for (int y = 0; y * y <= e - Z; y++) {
        int Y = y * y;
        for (int x = 0; x <= e - Y - Z; x++) {
          int X = x;
          if (X + Y + Z != e)
            continue;
          ans = min(ans, x + y + z);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#define rep(i, j) for (int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
using namespace std;
int main() {
  int e;
  while (cin >> e && e != 0) {
    int m = 214214, x = 0;
    rep(z, 111) rep(y, 1111) {
      x = e - (y * y + z * z * z);
      if (e == x + (y * y) + (z * z * z) && x >= 0) {
        m = min(x + y + z, m);
      }
    }
    printf("%d\\n", m);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#define rep(i, j) for (int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
using namespace std;
int main() {
  int e;
  while (cin >> e && e != 0) {
    int m = 214214, x = 0;
    rep(z, 1000) rep(y, 10000) {
      x = e - (y * y + z * z * z);
      if (e == x + (y * y) + (z * z * z) && x >= 0) {
        m = min(x + y + z, m);
      }
    }
    printf("%d\\n", m);
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define FOR(I, F, N) for (int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout << V << endl
#define pb push_back
#define INF (1 << 28)

template <typename T> void remove(vector<T> &vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void) {

  int e;
  while (cin >> e, e) {
    int min = e;
    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;
        if (x + y + z < min) {
          min = x + y + z;
        }
      }
    }
    cout << min << endl;
  }

  return 0;
}

int StrToInt(string s) {
  stringstream ss;
  ss << s;
  int val;
  ss >> val;
  return val;
}
string IntToStr(int i) {
  stringstream ss;
  ss << i;
  return ss.str();
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define FOR(I, F, N) for (int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout << V << endl
#define pb push_back
#define INF (1 << 28)

template <typename T> void remove(vector<T> &vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void) {
  int e;
  while (cin >> e, e) {
    int mini = e;
    for (int z = 0; e >= pow(z, 3); z++) {
      for (int y = 0; e - pow(z, 3) >= pow(y, 2); y++) {
        int x = e - pow(z, 3) - pow(y, 2);
        if (x < 0)
          continue;
        mini = min(mini, x + y + z);
      }
    }
    cout << mini << endl;
  }

  return 0;
}

int StrToInt(string s) {
  stringstream ss;
  ss << s;
  int val;
  ss >> val;
  return val;
}
string IntToStr(int i) {
  stringstream ss;
  ss << i;
  return ss.str();
}