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

#pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll, ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node *, Node *>
#define uid uniform_int_distribution
#define FILE                                                                   \\
  ifstream in("sumsqr.in");                                                    \\
  ofstream out("sumsqr.out");
#define fast                                                                   \\
  cin.tie(0);                                                                  \\
  cout.tie(0);                                                                 \\
  cin.sync_with_stdio(0);                                                      \\
  cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

ll x;

void check(ll d) {
  ll B = -2000;
  if (d > 3000)
    return;
  for (; B < 2000; B++) {
    ll A = B + d, pA = A * A * A * A * A, pB = B * B * B * B * B;
    // cout<<A<<" "<<B<<" "<<pA<<" "<<pB<<endl;
    if (pA - pB == x)
      cout << A << " " << B, exit(0);
    if (pA - pB > 1e18)
      return;
  }
}

int main() {
  fast;
  cin >> x;
  for (ll q = 1, g = sqrt(x); q <= g; q++) {
    if (x % q)
      continue;
    check(q);
    check(x / q);
  }
  assert(0);
}

Error: WA

Fixed submission:

#pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll, ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node *, Node *>
#define uid uniform_int_distribution
#define FILE                                                                   \\
  ifstream in("sumsqr.in");                                                    \\
  ofstream out("sumsqr.out");
#define fast                                                                   \\
  cin.tie(0);                                                                  \\
  cout.tie(0);                                                                 \\
  cin.sync_with_stdio(0);                                                      \\
  cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  fast;
  ll x;
  cin >> x;
  for (ll q = -2000; q < 2000; q++) {
    ll B = q * q * q * q * q, s = B + x, u = sqrtl(s);
    if (u * u * u * u * u == s) {
      cout << u << " " << q;
      exit(0);
    }
  }
  assert(0);
}