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

#include <cmath>
#include <iostream>
using namespace std;
int Bsearch(int n, int e) {
  if (e == 1)
    return 1;
  int s, t;
  s = 0;
  t = e;
  int x = e / 2;
  while (t - s > 1) {
    if (pow(x, n) < e) {
      s = x;
    } else if (pow(x, n) > e) {
      t = x;
    } else {
      break;
    }
    x = (s + t) / 2;
  }
  return x;
}

int main() {
  int e;
  while (cin >> e) {
    if (e == 0)
      break;
    int x = Bsearch(3, e);
    int y = Bsearch(2, e);
    int minim = 1000;
    for (int i = 0; i <= x; i++) {
      int z = pow(i, 3);
      for (int j = 0; j <= y; j++) {
        int x = e - z - j * j;
        if (x < 0)
          break;
        minim = min(minim, i + j + x);
      }
    }
    cout << minim << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int Bsearch(int n, int e) {
  if (e == 1)
    return 1;
  int s, t;
  s = 0;
  t = e;
  int x = e / 2;
  while (t - s > 1) {
    if (pow(x, n) < e) {
      s = x;
    } else if (pow(x, n) > e) {
      t = x;
    } else {
      break;
    }
    x = (s + t) / 2;
  }
  return x;
}

int main() {
  int e;
  while (cin >> e) {
    if (e == 0)
      break;
    int x = Bsearch(3, e);
    int y = Bsearch(2, e);
    int minim = 1000;
    for (int i = 0; i <= x; i++) {
      for (int j = 0; j <= y; j++) {
        int x = e - pow(i, 3) - pow(j, 2);
        if (x < 0)
          break;
        minim = min(minim, i + j + x);
      }
    }
    cout << minim << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

#define FOR(i, l, n) for (int(i) = (l); (i) < (n); (i)++)
#define REP(i, n) FOR(i, 0, n)

using namespace std;

int main() {
  long int x, y, z, e, m;
  while (cin >> e, e) {
    m = e;
    for (y = 0; y * y <= e; y++) {
      for (z = 0; z * z * z + y * y <= e; z++) {
        x = e - y * y - z * z * z;
        m = m < x + y + z ? m : x + y + z;
      }
    }
    cout << m << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>

#define FOR(i, l, n) for (int(i) = (l); (i) < (n); (i)++)
#define REP(i, n) FOR(i, 0, n)

#define MAX_Y 1000
#define MAX_Z 100
using namespace std;

int main() {
  long int x, y, z, e, m = 1000000;
  while (cin >> e, e) {
    FOR(y, 1, MAX_Y + 1) {
      FOR(z, 1, MAX_Z + 1) {
        x = e - pow(z, 3) - pow(y, 2);
        if (x >= 0 && x + y + z < m)
          m = x + y + z;
      }
    }
    cout << m << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main(int argc, char *argv[]) {
  int e;
  while (cin >> e, e) {
    int m = e;
    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;
        m = min(m, x + y + z);
      }
    }
    cout << m << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

using namespace std;

int main(int argc, char *argv[]) {
  int e;
  while (cin >> e, e) {
    int m = 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);
        m = min(m, x + y + z);
      }
    }
    cout << m << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int find(int e) {
  int m = 1000000;
  for (int z = 0; z <= 100; z++) {
    int r = e - z * z * z;
    if (r < 0)
      break;
    for (int y = 0; y <= 1000; y++) {
      int x = r - y * y;
      if (x < 0)
        break;
      m = min(m, x + y + z);
    }
  }
  return m;
}

int main() {
  int e;
  while (cin >> e, e)
    cout << find(e) << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int find(int e) {
  int m = 1000000;
  for (int z = 0; z <= 100; z++) {
    int r = e - z * z * z;
    if (r < 0)
      break;
    for (int y = 0; y <= r; y++) {
      int x = r - y * y;
      if (x >= 0)
        m = min(m, x + y + z);
    }
  }
  return m;
}

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

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

int main() {
  int e;
  while (cin >> e && e > 0) {
    unsigned int m = e;
    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 >= 0) {
          unsigned int sum = x + y + z;
          m = min(m, sum);
        }
      }
    }
    cout << m << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int e;
  while (cin >> e && e > 0) {
    int m = e ^ 3;
    REP(z, e) {
      REP(y, e) {
        int x = e - y * y - z * z * z;
        if (x >= 0) {
          int sum = x + y + z;
          m = min(m, sum);
        }
      }
    }
    cout << m << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define all(a) a.begin(), a.end()
#define len(x) ((int)(x).size())
#define tmax(a, b, c) max((a), max((b), (c)))
#define tmin(a, b, c) min((a), min((b), (c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<vector<int>> VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int main() {
  while (1) {
    int e;
    cin >> e;
    if (!e)
      break;
    int ans = inf;
    rep(i, 0, 1001) {
      rep(j, 0, 1001) {
        int l = 0;
        int r = 1000;
        int x = i * i * i + j * j;
        if (x > e)
          continue;
        rep(k, 0, 12) {
          int m = (l + r) / 2;
          if (x + m == e) {
            // printf("i=%d j=%d m=%d\\n",i,j,m);
            ans = min(ans, i + j + m);
          } else if (x + m > e)
            r = m;
          else
            l = m;
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define all(a) a.begin(), a.end()
#define len(x) ((int)(x).size())
#define tmax(a, b, c) max((a), max((b), (c)))
#define tmin(a, b, c) min((a), min((b), (c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<vector<int>> VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int main() {
  while (1) {
    int e;
    cin >> e;
    if (!e)
      break;
    int ans = inf;
    rep(i, 0, 1001) {
      rep(j, 0, 1001) {
        int l = 0;
        int r = 1000;
        rep(k, 0, 10) {
          int m = (l + r) / 2;
          int x = i * i * i + j * j + k;
          if (x == e) {
            ans = min(ans, i + j + k);
          } else if (x > e)
            r = m;
          else
            l = m;
        }
      }
    }
    cout << ans << endl;
  }

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

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30

using namespace std;
typedef long long ll;

int main() {
  int n;
  while (cin >> n && n) {
    int ans = INF;
    rep(i, 101) {
      if (i * i * i > n)
        break;

      rep(j, 1001) {
        if (i * i * i + j * j > n)
          break;
        ans = min(ans, i + j + (n - i * i * i - j * j));
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30

using namespace std;
typedef long long ll;

int main() {
  int n;
  while (cin >> n && n) {
    int ans = INF;
    rep(i, 100000) {
      if (i > n)
        break;
      rep(j, 100000) {
        if (i + j * j > n)
          break;
        rep(k, 100000) {
          if (i + j * j + k * k * k > n)
            break;
          if (i + j * j + k * k * k == n) {
            ans = min(ans, i + j + k);
            break;
          }
        }
      }
    }

    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;
  cin >> e;

  while (e) {
    int x = 0;
    int y = 0;
    int z = 0;
    int m = 0;
    for (z = 0; z * z * z <= e; z++)
      for (y = 0; z * z * z + y * y <= e; y++) {
        x = e - z * z * z - y * y;
        if (x < 0)
          continue;

        int t = x + y + z;
        if (m == 0 || m > t)
          m = t;
      }

    cout << m << endl;

    cin >> e;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int e;
  cin >> e;

  while (e) {
    int x = 0;
    int y = 0;
    int z = 0;
    int m = 0;
    for (z = 0; z <= e / 9; z++)
      for (y = 0; y <= e / 2; y++) {
        x = e - z * z * z - y * y;
        if (x < 0)
          continue;

        int t = x + y + z;
        if (m == 0 || m > t)
          m = t;
      }

    cout << m << endl;

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

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

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

int main() {
  int e;
  while (1) {
    std::cin >> e;
    if (!e)
      break;
    int m = 1000001;
    for (int i = 0; i * i * i <= e; i++) {
      for (int ii = 0; i * i * i + ii * ii <= e; ii++) {
        int x = e - i * i * i - ii * ii;
        int tmp = i + ii + x;
        if (tmp < m)
          m = tmp;
      }
    }
    std::cout << m << std::endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

int main() {
  int e;
  while (1) {
    std::cin >> e;
    if (!e)
      break;
    int m = 1000001;
    for (int i = 0; i * i * i <= e; i++) {
      for (int ii = 0; i * i * i + ii * ii <= e; ii++) {
        for (int i3 = 0; i * i * i + ii * ii + i3 <= e; i3++) {
          if (i * i * i + ii * ii + i3 == e) {
            int tmp = i + ii + i3;
            if (tmp < m)
              m = tmp;
          }
        }
      }
    }
    std::cout << m << std::endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int e;
  while (scanf("%d", &e) != EOF && e) {
    int m = 1000;
    for (int z = 100; z >= 0; z--) {
      if (e < z * z * z) {
        continue;
      }
      for (int y = 0; y < m; y++) {
        if (e < y * y + z * z * z) {
          break;
        }
        int x = e - y * y - z * z * z;
        if (x + y + z < m) {
          m = x + y + z;
        }
      }
    }
    printf("%d\\n", m);
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int e;
  while (scanf("%d", &e) != EOF && e) {
    int m = 1000;
    for (int z = 100; z >= 0; z--) {
      if (e < z * z * z) {
        continue;
      }
      for (int y = 0; y < m; y++) {
        if (e < y * y + z * z * z) {
          break;
        }
        for (int x = 0; x < m; x++) {
          if (e == x + y * y + z * z * z && x + y + z < m) {
            m = x + y + z;
          } else if (e < x + y * y + z * z * z) {
            break;
          }
        }
      }
    }
    printf("%d\\n", m);
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <vector>

using namespace std;

bool solve() {
  int n;
  cin >> n;
  if (!n)
    return false;
  int ans = 1000000;
  for (int k = 0; k * k * k <= n; k++) {
    for (int j = 0; j * j + k * k * k <= n; j++) {
      int i = n - j * j - k * k * k;
      if (0 <= i && i <= n) {
        int m = i + j + k;
        ans = min(ans, m);
      }
    }
  }
  cout << ans << endl;
  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);
  while (solve())
    ;

  return 0;
}


Error: TLE

Fixed submission:


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <vector>

using namespace std;

bool solve() {
  int n;
  cin >> n;
  if (!n)
    return false;
  int ans = 1000000;
  for (int k = n; k >= 0; k--) {
    if ((long long)k * k * k > n)
      continue; // long long
    for (int j = n; j >= 0; j--) {
      if ((long long)j * j + (long long)k * k * k > n)
        continue; //
      int i = n - j * j - k * k * k;
      if (0 <= i && i <= n) {
        int m = i + j + k;
        ans = min(ans, m);
      }
    }
  }
  cout << ans << endl;
  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);
  while (solve())
    ;

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

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

int e;

int main() {
  while (1) {
    scanf("%d", &e);
    if (e == 0)
      return 0;

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

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

Error: TLE

Fixed submission:

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

int e;

int main() {
  while (1) {
    scanf("%d", &e);
    if (e == 0)
      return 0;

    int ans = e;
    for (int z = 0; z * z * z <= e; z++) {
      int z3 = z * z * z;
      for (int y = 0; y * y + z3 <= e; y++) {
        int y2 = y * y;
        for (int x = 0; x + y2 + z3 <= e; x++) {
          if (x + y2 + z3 == e)
            ans = min(ans, x + y + z);
        }
      }
    }

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

#include "bits/stdc++.h"
#define ALL(a) (a).begin(), (a).end()
#define debug(x) cout << #x << " : " << (x) << " --------------" << endl;
using namespace std;

int main(void) {
  int e;
  while (cin >> e, e) {
    int m = 1000000;
    for (int z = 100; z >= 0; --z) {
      int val = z * z * z;
      if (val > e)
        continue;
      for (int y = sqrt(e - val); y >= 0; --y) {
        int val2 = val + y * y;
        if (val2 > e)
          continue;
        m = min(m, (e - val2) + y + z);
      }
    }
    cout << m << endl;
  }
  return EXIT_SUCCESS;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#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 debug(x) cout << #x << " : " << (x) << " --------------" << endl;
using namespace std;
struct Point {
  int l;
  int h;
};
bool operator<(const Point &lhs, const Point &rhs) {
  return tie(lhs.l, lhs.h) < tie(rhs.l, rhs.h);
}
int main(void) {
  int e;
  while (cin >> e, e) {
    int m = 1000000;
    REP(x, 1000001) {
      if (x > e || x > m)
        break;
      REP(y, 1001) {
        int tmp = x + y * y;
        if (tmp > e || x + y > m)
          break;
        REP(z, 101) {
          int val = tmp + z * z * z;
          if (val == e)
            m = min(m, x + y + z);
          else if (val > e || x + y + z > m)
            break;
        }
      }
    }
    cout << m << endl;
  }
  return EXIT_SUCCESS;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int x, y, z, minm = 100000000, e;
  while (true) {
    minm = 1000000;
    cin >> e;
    if (e == 0)
      break;
    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 (x >= 0)
          minm = min(minm, x + y + z);
      }
    }
    cout << minm << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  long x, y, z, min = 1000000, e, result[100000], cnt = 0;
  while (true) {
    min = 1000000;
    cin >> e;
    if (e == 0)
      break;
    // x,y,zが最小になる値を算出する
    for (y = 0; y < 1000; y++) {
      for (z = 0; z < 100; z++) {
        x = e - pow(y, 2) - pow(z, 3);
        if (x < 0)
          continue;
        if (e == (x + pow(y, 2) + pow(z, 3)) && min > x + y + z) {
          min = x + y + z;
          // printf("x:%ld y:%ld z:%ld Min is now %ld\\n",x,y,z,min);
        }
      }
    }
    result[cnt] = min;
    cnt++;
  }
  for (int i = 0; i < cnt; i++) {
    cout << result[i] << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define REP(i, n, N) for (int i = n; i < N; i++)
#define p(S) cout << S << endl
#define mp(a, b) make_pair(a, b)
using namespace std;

int main() {
  int e;
  while (cin >> e, e) {
    int mini = 1000000;
    int k;
    for (int z = 0; (k = e - z * z * z) >= 0; z++) {
      int y = (int)sqrt(k) + 0.00001;
      int x = k - y * y;
      mini = min(mini, x + y + z);
    }
    p(mini);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n, N) for (int i = n; i < N; i++)
#define p(S) cout << S << endl
#define mp(a, b) make_pair(a, b)
using namespace std;

int main() {
  int e;
  while (cin >> e, e) {
    int mini = 1000000;
    for (int x = 0; x <= e; x++) {
      for (int y = 0; x + y * y <= e; y++) {
        for (int z = 0; x + y * y + z * z * z <= e; z++) {
          if (x + y * y + z * z * z == e)
            mini = min(mini, x + y + z);
        }
      }
    }
    p(mini);
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
using namespace std;
int E;
int solve(int e) {
  int mi = e;
  for (int z = 0; z * z * z <= e; z++) {
    for (int y = 0; y * y <= e; y++) {
      if (e - y * y - z * z * z >= 0) {
        mi = min(mi, e - y * y - z * z * z + y + z);
      }
    }
  }
  return mi;
}
int min(int a, int b) {
  if (a < b)
    return a;
  else
    return b;
}
int main() {
  while (cin >> E && E > 0) {
    cout << solve(E) << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;
int E;
int solve(int e) {
  int mi = e;
  for (int x = 0; x <= e; x++) {
    for (int y = 0; y * y <= e; y++) {
      int z = round(pow(e - x - y * y, 1.0 / 3.0));
      if (x + y * y + z * z * z == e) {
        mi = min(mi, x + y + z);
      }
    }
  }
  return mi;
}
int min(int a, int b) {
  if (a < b)
    return a;
  else
    return b;
}
int main() {
  while (cin >> E && E > 0) {
    cout << solve(E) << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int E;
  while (cin >> E) {
    if (E == 0)
      break;
    int min = E;
    int sum;
    for (int z = 0; z * z * z <= E; ++z) {
      int y = sqrt(E - z * z * z);
      int x = E - z * z * z - y * y;
      sum = x + y + z;
      if (min > sum)
        min = sum;
    }
    cout << min << endl;
  }
  return 0;
}

Error: 1

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int E;
  cin >> E;
  int min = E;
  int sum;
  for (int z = 0; z <= 100; z++) {
    for (int y = 0; y * y < E - z * z * z; y++) {
      sum = (E - y * y - z * z * z) + y + z;
      if (min > sum)
        min = sum;
    }
  }
  return min;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
/*
int pow(int a,int b){
    int R=1;
    while(b){
        if(b&1) R=(R*a);
        a=(a*a);
        b>>=1;
    }
    return R;
}
*/
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int e;
  while (cin >> e, e) {
    int m = 1e+9;
    /*
    for(int z=0 , z1=0 ; z<=e; ++z1 , z=z1*z1*z1){
            for(int y=0 , y1=0 ; y<=e; ++y1 , y=y1*y1){
                    int x=e-y-z;
                    if(x>=0) m = min(m , x+(int)sqrt(y)+(int)cbrt(z));
            }
    }
    */
    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;
        if (x >= 0)
          m = min(m, x + y + z);
      }
    }
    cout << m << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

inline bool isint(double x) {
  int a = (int)x;
  if (a == x)
    return true;
  return false;
}

int main() {
  int e;
  while (cin >> e, e) {
    int m = 1e+9;
    for (int z = 0, z1 = 0; z <= e; ++z1, z = pow(z1, 3.)) {
      for (int y = 0, y1 = 0; y <= e; ++y1, y = pow(y1, 2.)) {
        int x = e - (y + z);
        if (x >= 0 && isint(cbrt(z)))
          m = min(m, x + (int)sqrt(y) + (int)cbrt(z));
      }
    }
    cout << m << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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