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

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

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define int long long

const int N = 2e5 + 5;

int n, m, k, ans = 0;
int a[N], b[N];

int32_t main() {
  IOS;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  int ans = 0;
  int idx = m;
  for (int i = 0; i <= n; i++) {
    if (a[i] > k)
      break;
    while (a[i] + b[idx] > k)
      idx--;
    ans = max(ans, i + idx);
  }
  cout << ans;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr << #x << ": " << x << " " << endl
#define tarce(x) cerr << #x << ": " << x << " " << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z)                                                        \\
  cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \\
       << z << endl
#define trace4(a, b, c, d)                                                     \\
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \\
       << c << " | " << #d << ": " << d << endl
#define sa(a, n)                                                               \\
  for (int i = 0; i < n; i++)                                                  \\
  cin >> a[i]
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define inf 2e18
#define scan()                                                                 \\
  int n;                                                                       \\
  cin >> n;                                                                    \\
  int a[n + 1];                                                                \\
  for (int i = 1; i <= n; i++)                                                 \\
  cin >> a[i]
#define scan2()                                                                \\
  int n, k;                                                                    \\
  cin >> n >> k;                                                               \\
  int a[n + 1];                                                                \\
  for (int i = 1; i <= n; i++)                                                 \\
  cin >> a[i]
#define print(a, n)                                                            \\
  for (int i = 0; i < n; i++)                                                  \\
  cout << a[i] << ' '
#define mem(a, v) memset(a, v, sizeof(a))
#define pii pair<int, int>
#define mkp make_pair
using namespace std;
#define N 200005

void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  int i, a[n + 1], b[n + 1], j;
  for (i = 1; i <= n; i++)
    cin >> a[i];
  for (i = 1; i <= m; i++)
    cin >> b[i];
  int ans = 0;
  i = 1;
  j = 1;
  while (k > 0) {
    int q = inf, w = inf;
    if (i <= n)
      q = a[i];
    if (j <= m)
      w = b[j];
    int r = min(q, w);
    if (k >= r) {
      ans++;
      if (r == q)
        i++;
      else
        j++;
      k = k - r;
    } else {
      break;
    }
  }
  cout << ans << '\\n';
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int tt;
  tt = 1;
  // cin >> tt;
  while (tt--) {
    solve();
  }
}