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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> pii;

int main() {
  int e;

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> pii;

int main() {
  int e;

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

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

using namespace std;

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

Error: TLE

Fixed submission:

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

using namespace std;

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

#include <climits>
#include <cmath>
#include <iostream>

using namespace std;

const int eMax = 1000000;

int main() {
  int e;
  while (cin >> e && e) {
    int ans = 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 + y + z < ans) {
          ans = x + y + z;
        }
      }
    }
    /*
    int ans = INT_MAX;
    bool flag = false;
    for(int x=0; x<e; x++) {
      for(int y=0; y<=sqrt(e) && x+y*y<=e; y++) {
        int yy = y*y;
        for(int z=0; z<=pow(e,0.333)+1 && x+yy+z*z*z<=e; z++) {
          int zzz = z*z*z;
          if(x+yy+zzz==e && x+y+z<ans) {
            ans = x+y+z;
          }
          if(flag == true) break;
        }
        if(flag == true) break;
      }
      if(flag == true) break;
    }
    */
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <climits>
#include <cmath>
#include <iostream>
#include <map>

using namespace std;

const int eMax = 1000000;

int main() {
  int e;
  while (cin >> e && e) {
    int ans = INT_MAX;
    bool flag = false;
    for (int x = 0; x < e; x++) {
      for (int y = 0; y <= sqrt(e) && x + y * y <= e; y++) {
        int yy = y * y;
        for (int z = 0; z <= pow(e, 0.333) + 1 && x + yy + z * z * z <= e;
             z++) {
          int zzz = z * z * z;
          if (x + yy + zzz == e && x + y + z < ans) {
            ans = x + y + z;
          }
          if (flag == true)
            break;
        }
        if (flag == true)
          break;
      }
      if (flag == true)
        break;
    }
    cout << ans << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(t, i, c) for (t::iretator i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

const double EPS = 1e-10;

int main() {
  int e;

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

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

    cout << min << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(t, i, c) for (t::iretator i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

const double EPS = 1e-10;

int main() {
  int e;

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

    for (int z = 100; z >= 0; z--) {
      for (int y = sqrt((double)e - z * z * z); y >= 0; y--) {
        for (int x = e - z * z * z - y * y; x >= 0; x--) {
          if (e == x + y * y + z * z * z) {
            if (min > x + y + z) {
              min = x + y + z;
            }
          }
        }
      }
    }

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

#include <algorithm>
#include <iostream>
#include <math.h>
#define MAX 1000000;
using namespace std;

int main() {
  long e;
  while (cin >> e && e != 0) {
    int min_m = MAX;
    for (int z = 0; z * z * z <= e; z++) {
      int y = sqrt(e - z * z * z);
      int x = e - (z * z * z) - (y * y);
      min_m = min(min_m, x + y + z);
    }
    cout << min_m << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#define MAX 10000000L;
using namespace std;

int main() {
  long e;
  while (cin >> e && e != 0) {
    long min_m = MAX;

    bool flag = false;
    for (long m = 1; m < 1000; m++) {
      for (int z = 0; z <= m; z++) {
        for (int y = 0; y <= m - z; y++) {
          int x = m - z - y;
          if (e == x + y * y + z * z * z) {
            min_m = m;
            flag = true;
            break;
          }
        }

        if (flag)
          break;
      }

      if (flag)
        break;
    }

    cout << min_m << endl;
  }

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

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

int main() {
  int e;
  while (cin >> e, e) {
    int x, y, z;
    int m = 10000;
    for (int i = 0; i * i * i <= e; ++i) {
      for (int j = 0; j * j <= e - (i * i * i); ++j) {
        int k = e - j * j - i * i * i;
        m = min(m, i + j + k);
      }
    }
    cout << m << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int e;
  while (cin >> e, e) {
    int x, y, z;
    int min = 10000;
    for (int i = 0; i * i * i <= e; ++i) {
      for (int j = 0; j * j <= e - (i * i * i); ++j) {
        for (int k = 0; k <= e - (i * i * i) - (j * j); ++k) {
          if (e == i * i * i + j * j + k && min > i + j + k) {
            min = i + j + k;
            // break;
          }
        }
        // if(min != 10000)break;
      }
      // if(min != 10000)break;
    }
    cout << min << endl;
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define INF 10000000
typedef long long ll;

// x^t
ll mypow(ll x, ll t) { return (ll)pow((double)x, (double)t); }

ll ans[1000001];

int main() {
  for (ll i = 0; i <= 1000000; i++)
    ans[i] = INF;
  for (ll z = 0; mypow(z, 3) <= 1000000; z++) {
    ll tmp;
    for (ll y = 0; (tmp = mypow(z, 3) + mypow(y, 2)) <= 1000000; y++)
      if (ans[tmp] > y + z)
        ans[tmp] = y + z;
  }
  while (true) {
    ll e;
    cin >> e;
    if (e == 0)
      break;
    ll mn = INF;
    for (int i = 0; i <= e; i++)
      if (mn > ans[i] + (e - i))
        mn = ans[i] + (e - i);
    cout << mn << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long ll;

// x^t
ll mypow(ll x, ll t) { return (ll)pow((double)x, (double)t); }

int main() {
  while (true) {
    ll e;
    cin >> e;
    if (e == 0)
      break;
    ll x, y, z;
    for (x = 0; x <= e; x++)
      for (y = 0; mypow(y, 2) + x <= e; y++)
        for (z = 0; pow(z, 3) + pow(y, 2) + x <= e; z++)
          if (mypow(z, 3) + mypow(y, 2) + x == e) {
            cout << x + y + z << endl;
            x = e + 1;
          }
  }
  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 ans = 1000000;
    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;
        ans = min(ans, x + y + z);
      }

    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

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

int main() {
  int e;
  while (true) {
    scanf("%d", &e);
    if (e == 0)
      break;
    int m = e;
    int vmin = -1;
    for (int z = 0; z * z * z <= e; ++z) {
      for (int y = 0; y * y + z * z * z <= e; ++y) {
        int x = e - z * z * z - y * y;
        if (m > x + y + z)
          m = x + y + z;
      }
    }
    cout << m << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int e;
  while (true) {
    scanf("%d", &e);
    if (e == 0)
      break;
    int vmin = -1;
    for (int yi = 0; yi <= sqrt(e); ++yi) {
      for (int zi = 0; zi <= pow(e, 1.0 / 3.0); ++zi) {
        int xi = e - yi * yi - zi * zi * zi;
        if (xi < 0)
          continue;
        if (xi + yi * yi + zi * zi * zi == e) {
          if (vmin == -1)
            vmin = xi + yi + zi;
          else
            vmin = min(vmin, xi + yi + zi);
        }
      }
    }
    cout << vmin << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using ll = long long;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)

int read() {
  int i;
  scanf("%lld", &i);
  return i;
}

signed main() {
  while (true) {
    int e = read();
    int ans = 100000;
    int m;
    if (e == 0)
      break;
    int z, y, x;
    for (z = 1; z * z * z < e; z++) {
    }
    for (y = 1; y * y < e; y++) {
    }
    for (int i = 0; i <= z; i++) {
      for (int j = 0; j <= y; j++) {
        if (e - i * i * i - j * j >= 0) {
          x = e - i * i * i - j * j;
          ans = min(ans, x + j + i);
        }
      }
    }

    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

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

using ll = long long;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)

int read() {
  int i;
  scanf("%lld", &i);
  return i;
}

signed main() {
  while (true) {
    int e = read();
    int ans = 100000;
    int m;
    if (e == 0)
      break;
    int z, y, x;
    for (z = 1; z * z * z < e; z++) {
    }
    for (y = 1; y * y < e; y++) {
    }
    for (int i = 0; i <= z; i++) {
      for (int j = 0; j <= y; j++) {
        for (x = 0; x + j * j + i * i * i <= e; x++) {
          if (x + j * j + i * i * i == e)
            ans = min(ans, x + j + i);
        }
      }
    }

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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep2(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

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

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

Error: TLE

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep2(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

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

  int e;
  while (cin >> e, e) {
    int m = 99999999;
    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) {
            m = min(m, x + y + z);
          }
        }
      }
    }
    cout << m << endl;
  }
}
Problem p01137 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
using namespace std;

int main() {
  long long sum, E;
  int y, z;
  while (scanf("%lld", &E), E) {
    sum = 1000000;
    for (z = 0; z * z * z <= E; z++)
      for (y = 0; y * y <= E; y++) {
        long long x = E - z * z * z - y * y;
        if (x < 0) {
          break;
        } else if (sum > (x + y + z))
          sum = x + y + z;
      }
    printf("%lld\\n", sum);
  }

  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main() {
  long long E, sum = 1000000;
  int y, z;
  long long x = E - z * z * z - y * y;
  while (scanf("%lld", E)) {
    if (E == 0)
      break;
    for (z = 0; z * z * z <= E; z++)
      for (y = 0; y * y <= E; y++) {
        if (z * z * z + y * y > E)
          break;
        else if (sum > x + y + z)
          sum = x + y + z;
      }
    printf("%lld", sum);
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int e;
  while (true) {
    cin >> e;
    if (e == 0) {
      break;
    }
    int x = 0, y = 0, z = 0;

    int ans = e;

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

    cout << ans << endl;
    /*
    for(x=0;x<=e;x++){
            for(y=0;y*y+x<=e;y++){
                    for(z=0;z*z*z+y*y+x<=e;z++){
                            if(z*z*z+y*y+x==e){
                                    ans = min(ans,x+y+z);
                            }
                    }
            }
    }
    cout << ans << endl;
    */
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int e;
  while (true) {
    cin >> e;
    if (e == 0) {
      break;
    }
    int x = 0, y = 0, z = 0;

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

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

// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// debug
#define DUMP(x) cerr << #x << " = " << (x) << endl;
#define DEBUG(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

const int MILLION = 1000000;
int main() {
  int result = 1000000;
  int input;
  bool flag = true;
  while (cin >> input && input) {
    for (int i = 0; i * i * i <= input; i++) {
      for (int j = 0; j * j <= input - i * i * i; j++) {
        //		    if(i*i*i+j*j+k==input)
        int k = input - i * i * i - j * j;
        int temp = i + j + k;
        result = min(result, temp);
      }
    }
    cout << result << endl;
    result = 1000000;
  }
  return 0;
}

Error: TLE

Fixed submission:

// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// debug
#define DUMP(x) cerr << #x << " = " << (x) << endl;
#define DEBUG(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

const int MILLION = 1000000;
int main() {
  int result;
  int input;
  bool flag = true;
  //    priority_queue<int> results;
  //    set<int> results;
  vector<int> results;
  while (cin >> input && input) {
    for (int i = 0; i * i * i <= input; i++) {
      for (int j = 0; j * j <= input - i * i * i; j++) {
        for (int k = 0; k <= input - i * i * i - j * j; k++) {
          if (i * i * i + j * j + k == input)
            results.push_back(i + j + k);
        }
      }
    }
    //	cout << "test" << endl;
    sort(results.begin(), results.end());

    //	result = *results.begin();
    cout << results[0] << endl;
    results.clear();
  }
  return 0;
}
Problem p01137 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int e, m;

  while (cin >> e && e > 0) {
    m = e;
    for (int z = 0; pow(z, 3) <= e; z++) {
      int pz = pow(z, 3);
      for (int y = 0; pz + pow(y, 2) <= e; y++) {
        int x = e - (pz + pow(y, 2));
        if (x + y + z < m)
          m = x + y + z;
      }
    }
    cout << m << endl;
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int e, m;

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

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
#define PB push_back
#define in scanf
#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--)
using namespace std;
void solve() {
  int e;
  while (cin >> e, e != 0) {
    int m = 1000000000;
    int x;
    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;
        m = min(x + y + z, m);
      }
    }
    cout << m << endl;
  }
}

int main() { solve(); }

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
#define PB push_back
#define in scanf
#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--)
using namespace std;
void solve() {
  int e;
  while (cin >> e, e != 0) {
    int m = 1000000000;
    int x;
    REP(z, (int)pow(e, 0.333) + 1) {
      REP(y, (int)pow(e, 0.5) + 1) {
        x = e - pow(y, 2) - pow(z, 3);
        if (x >= 0)
          m = min(x + y + z, m);
      }
    }
    cout << m << endl;
  }
}

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

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