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

/*** akshaykumar99 ***/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using id_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define f(i, x, n) for (i = x; i < n; i++)
#define fr(i, x, n) for (i = x; i >= n; i--)
#define pu push_back
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define SP(x) fixed << setprecision(x)
#define IOS()                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

const long long MOD = 1e9 + 7;
const long double PI = acos(-1);
const long long INF = INT_MAX;
const long long LINF = LLONG_MAX;
const long long N = 2e6 + 1;

typedef long long ll;
typedef long double ld;

void test_case() {
  ll n, m, i, j, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  f(i, 0, n) {
    cin >> a[i];
    if (i)
      a[i] += a[i - 1];
  }
  f(i, 0, m) {
    cin >> b[i];
    if (i)
      b[i] += b[i - 1];
  }
  ll st1 = 0, st2 = 0, ans = 0, tot = 0;
  ll x = upper_bound(all(b), k) - b.begin();
  ans = x;
  f(i, 0, n) {
    ll req = k - a[i];
    ll x = 0;
    if (req > 0)
      x = upper_bound(all(b), req) - b.begin();
    if (req >= 0)
      ans = max(ans, i + 1 + x);
  }
  cout << ans << '\\n';
}

int32_t main() {
  IOS();

  int tc = 1;
  // cin>>tc;
  while (tc--)
    test_case();
  return 0;
}


Error: -11

Fixed submission:

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

#define endl '\\n'
#define ll long long
#define rint register int
#define minpq priority_queue<int, vector<int>, greater<int>>
#define maxpq priority_queue<int>

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\\n';

using db = long double;
using pll = pair<ll, ll>;
#define scan(a, n)                                                             \\
  for (int i = 0; i < n; i++)                                                  \\
    cin >> a[i];

#define rep(i, x, n, inc) for (i = x; i < n; i += inc)
#define repr(i, x, n, inc) for (i = x; i > n; i += inc)
#define all(a) (a).begin(), (a).end()
#define unique_sort(x)                                                         \\
  sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a, b) make_pair(a, b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX

#define Foxen(i, s) for (i = s.begin(); i != s.end(); i++)
#define Fill(s, v) memset(s, v, sizeof(s))
#define cout_p(x, p)                                                           \\
  cout << fixed << setprecision((p)) << x << endl // print with precision

#define tc(tt)                                                                 \\
  ll tt;                                                                       \\
  cin >> tt;                                                                   \\
  for (ll _tt = 0; _tt < tt; _tt++) // testcase

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ll i, x, j, y, m, z = 0, k, n;
  string s, t;
  cin >> n >> m >> k;
  ll a[n + 1], b[m + 1];
  rep(i, 0, n, 1) cin >> a[i];
  rep(i, 0, m, 1) cin >> b[i];
  // scan(a, n);
  // scan(b, m);
  // a[n] = b[m] = infl;
  i = 0, j = 0;

  while (i <= n && j <= m && k >= min(a[i], a[j])) {
    if (j == m) {
      if (k >= a[i]) {
        k -= a[i];
        z++;
        i++;
      } else
        break;
    } else if (i == n) {
      if (k >= b[j]) {
        k -= b[j];
        z++;
        j++;
      } else
        break;
    } else if (a[i] >= b[j] && k >= b[j]) {
      // ce(j << " " << b[j])
      k -= b[j];
      z++;
      j++;
    } else if (a[i] <= b[j] && k >= a[i]) {
      // ce(i << " " << a[i])
      k -= a[i];
      z++;
      i++;
    } else
      break;
  }

  if (i == n) {

  } else if (j == m) {

  } else {
  }

  ce(z)
}