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

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int32_t main() {
  lli n, m, i, k, j, c = 0, v1 = 0, v2 = 0;
  cin >> n >> m >> k;
  lli a[n + 5];
  lli b[m + 5];
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (i != 1)
      a[i] += a[i - 1];
    if (k >= a[i])
      v1 = i;
  }
  for (i = 1; i <= m; i++) {
    cin >> b[i];
    if (i != 1)
      b[i] += b[i - 1];
    if (k >= b[i])
      v2 = i;
  }
  i = 1;
  j = m;
  c = max(v1, v2);
  while (i <= n && j >= 1) {
    if (a[i] + b[j] <= k) {
      c = max(c, i + j);
      i++;
    } else
      j--;
  }
  cout << c << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define IOS                                                                    \\
  std::ios::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
//    #define for(i,a,b)  for(int i=a;i<b;++i)
//    #define rev(i,a) for(int i=a-1;i>=0;i--)
#define fill(a, b) memset(a, b, sizeof(a))
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define mod 1000000007 // 998244353
#define maxn 1000005

// clear adj and visited vector declared globally after each test case
// check for long long overflow
// while adding and subs check if mod becomes -ve
// while using an integer directly in a builtin function add ll
// Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
// Dont keep array name as size or any other key word

using namespace std;
int power(int a, int b, int p) {
  if (a == 0)
    return 0;
  int res = 1;
  a %= p;
  while (b > 0) {
    if (b & 1)
      res = (res * a) % p;
    b >>= 1;
    a = (a * a) % p;
  }
  return res;
}

int lcm(int a, int b) {
  int g = __gcd(a, b);
  return a / g * b;
}

int solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  if (count(a.begin(), a.end(), a[0]) == n) {
    cout << 1 << endl;
    for (int i = 0; i < n; ++i) {
      cout << 1 << " ";
    }
    cout << endl;
    return 0;
  }

  if (n % 2 == 0) {
    cout << 2 << endl;
    for (int i = 0; i < n; ++i) {
      cout << i % 2 + 1 << " ";
    }
    cout << endl;
    return 0;
  }

  for (int i = 0; i < n; ++i) {
    if (a[i] == a[(i + 1) % n]) {
      vector<int> ans(n);
      for (int j = 0, pos = i + 1; pos < n; ++pos, j ^= 1) {
        ans[pos] = j + 1;
      }
      for (int j = 0, pos = i; pos >= 0; --pos, j ^= 1) {
        ans[pos] = j + 1;
      }
      cout << 2 << endl;
      for (int pos = 0; pos < n; ++pos) {
        cout << ans[pos] << " ";
      }
      cout << endl;
      return 0;
    }
  }

  cout << 3 << endl;
  for (int i = 0; i < n - 1; ++i) {
    cout << i % 2 + 1 << " ";
  }
  cout << 3 << endl;
  return 0;
}

int32_t main() {

  int q = 1;
  // cin >> q;
  for (int qq = 0; qq < q; qq++) {
    int n, m, k;
    cin >> n >> m >> k;
    list<int> a;
    list<int> b;
    for (int i = 0; i < n; i++) {
      int input;
      cin >> input;
      a.push_back(input);
    }
    for (int i = 0; i < m; i++) {
      int input;
      cin >> input;
      b.push_back(input);
    }

    int ts = 0;
    int count = 0;
    while (true) {
      if (a.front() <= b.front()) {
        if (a.front() <= k - ts) {
          ts += a.front();
          a.pop_front();
        } else {
          break;
        }
      } else {
        if (b.front() <= k - ts) {
          ts += b.front();
          b.pop_front();
        } else {
          break;
        }
      }

      count++;
    }

    cout << count << endl;
  }
}