Problem p02690 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define FAST                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef int32_t i32;

#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front

#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define RFOR(i, a, b) for (ll i = a; i >= b; i--)
#define FILL(a, b, c)                                                          \\
  for (ll i = 0; i < c; i++)                                                   \\
    a[i] = b;

#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

#define endl "\\n"
#define setpri(x) setprecision(x)
#define vp(x) cout << #x << " : " << (x) << " | "
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define forf(i, a, b) for (int i = a; i < b; i++)

#define INF 1e17 + 4
#define MINF
#define MAX_INT 100000
#define MOD 1000000007
ll mod(ll n) {
  n %= MOD;
  if (n < 0)
    return n + MOD;
  else
    return n;
}
vector<int> adj[1000002];
int vis[1000002], dep[1000002], siz[1000002];

// void dfs(ll cur,ll par)
// {
//     vis[cur]=1;siz[cur]=1;
//     for(auto x:adj[cur])
//     {
//         if(vis[x]!=1)
//         {
//             dep[x]=dep[cur]+1;
//             dfs(x,cur);
//             siz[cur]+=siz[x];
//         }
//     }
// }

// bool sortfunc(const pair<int,int> &a, const pair<int,int> &b)
// {
//     return ;
// }

void solve() {
  int y;
  cin >> y;
  vector<int> a;
  forf(i, 0, 1000) a.pb(pow(i, 5));

  for (int i = 0; i < 1000; i++) {
    int l = y + a[i];
    auto x = find(a.begin(), a.end(), l);
    if (x != a.end()) {
      cout << x - a.begin() << " " << i << endl;
      return;
    }
    l = y - a[i];
    if (l < 0)
      continue;
    x = find(a.begin(), a.end(), l);
    if (x != a.end()) {
      cout << x - a.begin() << " " << -i << endl;
      return;
    }
  }
}

signed main() {
  FAST;

  // ll t;cin>>t;while(t--)
  solve();

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FAST                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef int32_t i32;

#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front

#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define RFOR(i, a, b) for (ll i = a; i >= b; i--)
#define FILL(a, b, c)                                                          \\
  for (ll i = 0; i < c; i++)                                                   \\
    a[i] = b;

#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

#define endl "\\n"
#define setpri(x) setprecision(x)
#define vp(x) cout << #x << " : " << (x) << " | "
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define forf(i, a, b) for (int i = a; i < b; i++)

#define INF 1e17 + 4
#define MINF
#define MAX_INT 100000
#define MOD 1000000007
ll mod(ll n) {
  n %= MOD;
  if (n < 0)
    return n + MOD;
  else
    return n;
}
vector<int> adj[1000002];
int vis[1000002], dep[1000002], siz[1000002];

// void dfs(ll cur,ll par)
// {
//     vis[cur]=1;siz[cur]=1;
//     for(auto x:adj[cur])
//     {
//         if(vis[x]!=1)
//         {
//             dep[x]=dep[cur]+1;
//             dfs(x,cur);
//             siz[cur]+=siz[x];
//         }
//     }
// }

// bool sortfunc(const pair<int,int> &a, const pair<int,int> &b)
// {
//     return ;
// }

void solve() {
  int x;
  cin >> x;
  int a[41];
  forf(i, 0, 41) a[i] = pow(i, 5);
  int l = 0, r = x;
  // cout<<x;
  // cout<<log2(1e9)/log2(5);
  // cout<<a[40]<<endl;
  while (l <= r) {
    if ((a[r] + a[l]) == x) {
      cout << r << " " << -l;
      return;
    }
    if (a[l] + a[r] > x)
      r--;
    else
      l++;
  }
  l = 0, r = 0;
  // cout<<1;
  while (r < 41 && l < 41) {
    if ((a[r] - a[l]) == x) {
      cout << r << " " << l;
      return;
    }
    if (a[r] - a[l] < x)
      r++;
    else
      l++;
  }
  // cout<<2;
}

signed main() {
  FAST;

  // ll t;cin>>t;while(t--)
  solve();

  return 0;
}