prithivMLmods/Coder-Stat huggingface dataset:
Problem p01137 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#define ll long long
#define inf 1000000000
using namespace std;

int e;

int yy(int a) {
  int i = 0;
  while (i * i <= a) {
    if (i * i == a)
      return i;
    i++;
  }
  return inf;
}

int zzz(int a) {
  int i = 0;
  while (i * i * i <= a) {
    if (i * i * i == a)
      return i;
    i++;
  }
  return inf;
}

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

Fixed submission:
#include <bits/stdc++.h>

#define ll long long
#define inf 1000000000
using namespace std;

int e;

int yy(int a) {
  int i = 0;
  while (i * i <= a) {
    if (i * i == a)
      return i;
    i++;
  }
  return inf;
}

int zzz(int a) {
  int i = 0;
  while (i * i * i <= a) {
    if (i * i * i == a)
      return i;
    i++;
  }
  return inf;
}

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REAP(i, a, n) for (int i = (a); i < (n); i++)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(), v.end()
typedef long long ll;

int main() {
  ll e;
  while (cin >> e, e) {
    ll m = e;
    for (int y = 0; y * y <= e; y++) {
      for (int z = 0; z * z * z + y * y <= e; z++) {
        m = min(m, y + z + (e - (ll)pow(y, 2) - (ll)pow(z, 3)));
      }
    }
    cout << m << endl;
  }
}


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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REAP(i, a, n) for (int i = (a); i < (n); i++)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(), v.end()
typedef long long ll;

int main() {
  ll e;
  while (cin >> e, e) {
    ll m = e;
    for (int y = 0; y * y <= e; y++) {
      for (int z = 0; z * z * z + y * y <= e; z++) {
        m = min(m, y + z + (e - y * y - z * z * z));
      }
    }
    cout << m << endl;
  }
}
Problem p01137 (C++)

Buggy submission (status: 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++) {
        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;
  }
}

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++) {
        int x = e - z * z * z - y * y;
        if (x + y + z < ans)
          ans = x + y + z;
      }
    }
    cout << ans << endl;
  }
}
Problem p01137 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
  int e;
  while (cin >> e, e) {
    int m = 20000000;
    int x, y, z;

    for (z = 0; (int)pow(z, 3) <= e; z++) {
      for (y = 0; (int)pow(y, 2) + (int)pow(z, 3) <= e; y++) {
        x = e - ((int)pow(y, 2) + (int)pow(z, 3));
        m = min(m, x + y + z);
      }
    }
    cout << m << endl;
  }
  return 0;
}

Fixed submission:
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
  int e;
  while (cin >> e, e) {
    int m = 20000000;
    int x, y, z;

    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);
        m = min(m, x + y + z);
      }
    }
    cout << m << endl;
  }
  return 0;
}
Problem p01137 (C++)

Buggy submission (status: 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 <= 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;
}

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 * 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;
}
Problem p01137 (C++)

Buggy submission (status: 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++) {
        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;
}

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

    cout << ans << endl;
  }

  return 0;
}
Problem p01137 (C++)

Buggy submission (status: Time Limit Exceeded):
#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;
  }
}

Fixed submission:
#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;
  }
}
Problem p01137 (C++)

Buggy submission (status: 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 (i + pow(j, 2.0) + pow(k, 3.0) == e && answer > i + j + k) {
          answer = i + j + k;
        }
      }
    }

    cout << answer << endl;
  }

  return 0;
}


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 (answer > i + j + k) {
          answer = i + j + k;
        }
      }
    }

    cout << answer << endl;
  }

  return 0;
}
Problem p01137 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

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


Fixed submission:
#include <iostream>
using namespace std;

int main() {
  while (1) {
    int e, min = 100000000, ans;
    cin >> e;
    if (e == 0)
      break;
    for (int i = 0; i * i * i <= e; i++) {
      for (int j = 0; j * j <= e; j++) {
        ans = e - (i * i * i + j * j);
        if (min > ans + j + i && e >= ans && ans >= 0)
          min = ans + i + j;
      }
    }
    cout << min << endl;
  }
  return 0;
}
Problem p01137 (C++)

Buggy submission (status: 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 <= 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;
}


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 * 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;
}
Problem p01137 (C++)

Buggy submission (status: 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) {
      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;
  }
}

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) {
      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;
  }
}
Problem p01137 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  while (true) {
    int e;
    cin >> e;

    if (e == 0) {
      break;
    }

    int ans = e;

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

    cout << ans << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  while (true) {
    int e;
    cin >> e;

    if (e == 0) {
      break;
    }

    int ans = e;

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

    cout << ans << endl;
  }

  return 0;
}
Problem p01137 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cctype>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>

using namespace std;

int main(int argc, char const *argv[]) {
  int e;
  while (cin >> e, e) {
    int x, y, z;
    int m = 1000000;

    // for (int i = 0; i <= e; i++)
    //{
    //     for (int j = 0; j*j <= e; j++)
    //     {
    //         for (int k = 0; k*k*k <= e; k++)
    //         {
    //             //cout << " x y z = " << i << j << k <<endl;
    //             if ( i + j*j + k*k*k == e)
    //             {
    //                 m = min( m, i + j + k);
    //             }
    //         }
    //     }
    // }
    for (int k = 0; 0 <= k * k * k; k++) {
      int j = sqrt(e - k * k * k);
      int i = e - k * k * k - j * j;
      m = min(m, i + j + k);
    }
    cout << m << endl;
  }
  return 0;
}

Fixed submission:
#include <cctype>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>

using namespace std;

int main(int argc, char const *argv[]) {
  int e;
  while (cin >> e, e) {
    int x, y, z;
    int m = 1000000;

    // for (int i = 0; i <= e; i++)
    //{
    //     for (int j = 0; j*j <= e; j++)
    //     {
    //         for (int k = 0; k*k*k <= e; k++)
    //         {
    //             //cout << " x y z = " << i << j << k <<endl;
    //             if ( i + j*j + k*k*k == e)
    //             {
    //                 m = min( m, i + j + k);
    //             }
    //         }
    //     }
    // }
    for (int k = 0; k * k * k <= e; k++) {
      int j = sqrt(e - k * k * k);
      int i = e - k * k * k - j * j;
      m = min(m, i + j + k);
    }
    cout << m << endl;
  }
  return 0;
}
Problem p01137 (C++)

Buggy submission (status: 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;
    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;
}

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;
    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;
}
Problem p01137 (C++)

Buggy submission (status: 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 = 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;
}


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 = 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;
}
Problem p01137 (C++)

Buggy submission (status: 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;
        }
        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);
  }
}

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;
        }
        int x = e - y * y - z * z * z;
        if (x + y + z < m) {
          m = x + y + z;
        }
      }
    }
    printf("%d\n", m);
  }
}
Problem p01137 (C++)

Buggy submission (status: 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++) {
        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;
}

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++) {
        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;
}
Problem p01137 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

int e;

void solve() {
  int m = e;

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

  cout << m << endl;
}

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

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int e;

void solve() {
  int m = e;

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

  cout << m << endl;
}

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

  return 0;
}
Problem p01137 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

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

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

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

  while (cin >> e, e != 0) {
    m = INF;
    rep(i, 150) {
      rep(j, 150) {
        rep(k, 150) {
          if (i + j * j + k * k * k == e) {
            if (m > i + j + k) {
              m = i + j + k;
            }
          }
        }
      }
    }
    cout << m << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>

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

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

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

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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main() {
  int e;

  while (cin >> e, e) {
    for (int x = 0; x <= e; x++)
      for (int y = 0; y <= e; y++)
        for (int z = 0; z <= e; z++)
          if (x + y * y + z * z * z == e) {
            cout << x + y + z << endl;
            goto out;
          }
  out:;
  }

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int e;

  while (cin >> e, e) {
    int min_a = 1000000;
    int z_, y_;

    for (int z = 0; z * z * z <= e; z++)
      for (int y = 0; y * y + z * z * z <= e; y++) {
        if (min_a > z + y + e - y * y - z * z * z) {
          min_a = z + y + e - y * y - z * z * z;
          z_ = z;
          y_ = y;
        }
      }
    cout << e - y_ * y_ - z_ * z_ * z_ + y_ + z_ << endl;
  }

  return 0;
}
Problem p01137 (C++)

Buggy submission (status: 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, 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;
}

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, 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;
}
Problem p01137 (C++)

Buggy submission (status: 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;
    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;
}

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;
    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;
}
Problem p01137 (C++)

Buggy submission (status: 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 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;
  }
}

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 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;
  }
}
Problem p01137 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int main() {
  int e;
  while (scanf("%d", &e), e) {
    int m = 1 << 25;
    for (int i = 0; i <= e; i++) {
      for (int j = 0; i + j * j <= e; j++) {
        for (int k = 0; i + j * j + k * k * k <= e; k++) {
          if (i + j * j + k * k * k == e) {
            m = min(m, i + j + k);
          }
        }
      }
    }
    printf("%d\n", m);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int main() {
  int e;
  while (scanf("%d", &e), e) {
    int m = 1 << 25;
    for (int i = 0; i * i * i <= e; i++) {
      for (int j = 0; i * i * i + j * j <= e; j++) {
        int val = i * i * i + j * j;
        m = min(m, i + j + (e - val));
      }
    }
    printf("%d\n", m);
  }
  return 0;
}
Problem p01137 (C++)

Buggy submission (status: 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) {
      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;
}


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) {
      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;
}
Problem p01137 (C++)

Buggy submission (status: 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; 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;
}

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; 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;
}
Problem p01137 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
using namespace std;

int main() {

  int E, X, tempmin;
  int min;

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

Fixed submission:
#include <cmath>
#include <iostream>
using namespace std;

int main() {

  int E, X, tempmin;
  int min;

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

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


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

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
using namespace std;
int E;
int main() {
  while (cin >> E && E > 0) {
    int m = 500;
    for (int z = 0; z <= cbrt(E); z++) {
      if (z >= m)
        break;
      for (int y = 0; y <= sqrt(E - pow(z, 3)); y++) {
        if (y + z >= m)
          break;
        int x = E - pow(z, 3) - pow(y, 2);
        if (x >= 0) {
          if (x + y + z < m) {
            m = x + y + z;
          }
        }
      }
    }
    cout << m << endl;
  }
}

Fixed submission:
#include <cmath>
#include <iostream>
using namespace std;
int E;
int main() {
  while (cin >> E && E > 0) {
    int m = 1000000;
    for (int z = 0; z * z * z <= E; z++) {
      // if(z >= m) break;
      for (int y = 0; y * y <= E - z * z * z; y++) {
        // if (y+z >= m) break;
        int x = E - z * z * z - y * y;
        if (x >= 0) {
          if (x + y + z < m) {
            m = x + y + z;
          }
        }
      }
    }
    cout << m << endl;
  }
}
Problem p01137 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

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

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

  return 0;
}

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

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

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

  return 0;
}
Problem p01137 (C++)

Buggy submission (status: 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;
    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;
  }
}

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;
    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;
  }
}
Problem p01137 (C++)

Buggy submission (status: 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 <= 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;
  }
}

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 <= 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;
  }
}
Problem p01137 (C++)

Buggy submission (status: 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; 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;
}

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; 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;
}
Problem p01137 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    int ans = 1000000;
    for (int i = 0; i < 1000; i++) {
      if (n < pow(i, 2))
        break;
      for (int j = 0; j < 100; j++) {
        if (n - pow(i, 2) - pow(j, 3) < 0)
          continue;
        ans = min(ans, i + j + (int)(n - pow(i, 2) - pow(j, 3)));
      }
    }
    cout << ans << endl;
  }
}

Fixed submission:
#include <cmath>
#include <iostream>
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    int ans = 1 << 30;
    for (int i = 0; i * i * i <= n; i++) {
      int j = sqrt(n - i * i * i);
      if (n < i * i * i + j * j)
        continue;
      ans = min(ans, i + j + (n - i * i * i - j * j));
    }
    cout << ans << endl;
  }
}
Problem p01137 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for (LL i = 0; i < n; ++i)
#define FOR(i, a, n) for (LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

// #define int long long

/*************** using variables ***************/
int e;
int m = INF;
/**********************************************/

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

  while (cin >> e, e) {
    m = INF;
    for (int x = 0; x <= e; x++) {
      for (int y = 0; y * y <= e - x; y++) {
        int z3 = e - x - y * y;
        int z = cbrt(z3);
        if (z3 == z * z * z) {
          if (x + y * y + z * z * z == e) {
            // cout << x << " " << y << " " << z << endl;
            m = min(m, x + y + z);
          }
        }
      }
    }

    cout << m << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for (LL i = 0; i < n; ++i)
#define FOR(i, a, n) for (LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

// #define int long long

/*************** using variables ***************/
int e;
int m = INF;
/**********************************************/

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

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

    cout << m << endl;
  }
}
Problem p01137 (C++)

Buggy submission (status: 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 = 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;
  }
}

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 = 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;
  }
}
Problem p01137 (C++)

Buggy submission (status: Time Limit Exceeded):
#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;
          }
        }
  }
}

Fixed submission:
#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;
  }
}
Problem p01137 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;
int main() {
  int e;
  while (cin >> e && e > 0) {
    int min_sum = 100000;
    for (int i = 0; i <= e; i++) {
      int j = sqrt(e - i * i * i);
      int k = e - i * i * i - j * j;
      int temp = i + j + k;
      min_sum = min(temp, min_sum);
    }
    cout << min_sum << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;
int main() {
  int e;
  while (cin >> e && e > 0) {
    int min_sum = 100000;
    for (int i = 0; i * i * i <= e; i++) {
      int j = sqrt(e - i * i * i);
      int k = e - i * i * i - j * j;
      int temp = i + j + k;
      min_sum = min(temp, min_sum);
    }
    cout << min_sum << endl;
  }
}