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

#include <bits/stdc++.h>
#include <math.h>

using namespace std;
typedef long long ll;
#define M_PI 3.14159265358979323846

void solve() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  vector<ll> b(m);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < m; i++)
    cin >> b[i];
  vector<ll> sumA(n + 1);
  vector<ll> sumB(m + 1);
  for (int i = 0; i < n; i++)
    sumA[i + 1] = sumA[i] + a[i];
  for (int i = 0; i < m; i++)
    sumB[i + 1] = sumB[i] + b[i];
  int total = 0;
  for (int i = 0; i <= n; i++) {
    ll other = k - sumA[i];
    if (other < 0)
      continue;
    int l = lower_bound(sumB.begin(), sumB.end(), other) - sumB.begin();
    if (l > m || sumB[l] > other)
      --l;
    //            cout<<other<<" "<<l<<" "<<i<<" "<<"\\n";
    total = max(total, i + l);
  }
  cout << total;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout << setprecision(10);
  int t = 1;
  //        cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <deque>
#include <stdio.h>
#include <string>
#include <vector>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#include <set>
#define ws " "
#define nl "\\n"
#define tc                                                                     \\
  ll test;                                                                     \\
  cin >> test;                                                                 \\
  while (test--)
#define f(i, a, b) for (ll i = a; i < b; i++)
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
using namespace std;

#define pid pair<int, double>
bool compare(pid a, pid b) {
  // for descending order replace with a.roll >b.roll
  if (a.ss < b.ss)
    return 1;
  else
    return 0;
}

void fillPrefixSum(ll arr[], int n, ll prefixSum[]) {
  prefixSum[0] = arr[0];
  for (int i = 1; i < n; i++)
    prefixSum[i] = prefixSum[i - 1] + arr[i];
}

void SieveOfEratosthenes(ll n, bool prime[], bool primesquare[], ll a[]) {
  for (ll i = 2; i <= n; i++)
    prime[i] = true;
  for (ll i = 0; i <= (n * n + 1); i++)
    primesquare[i] = false;
  prime[1] = false;

  for (ll p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (ll i = p * 2; i <= n; i += p)
        prime[i] = false;
    }
  }

  ll j = 0;
  for (ll p = 2; p <= n; p++) {
    if (prime[p]) {
      a[j] = p;

      primesquare[p * p] = true;
      j++;
    }
  }
}

ll countDivisors(ll n) {
  if (n == 1)
    return 1;

  bool prime[n + 1], primesquare[n * n + 1];

  ll a[n]; // for storing primes upto n
  SieveOfEratosthenes(n, prime, primesquare, a);

  ll ans = 1;

  for (ll i = 0;; i++) {
    if (a[i] * a[i] * a[i] > n)
      break;
    ll cnt = 1;           // cnt is power of prime a[i] in n.
    while (n % a[i] == 0) // if a[i] is a factor of n
    {
      n = n / a[i];
      cnt = cnt + 1; // incrementing power
    }

    ans = ans * cnt;
  }
  if (prime[n])
    ans = ans * 2;

  // Second case
  else if (primesquare[n])
    ans = ans * 3;

  // Third casse
  else if (n != 1)
    ans = ans * 4;

  return ans; // Total divisors
}

bool checkLast(ll n) {
  if (n % 10 == 0)
    return true;
  return false;
}
bool checkPrime(ll n) {
  // Corner cases
  if (n <= 1)
    return false;
  if (n <= 3)
    return true;

  // This is checked so that we can skip
  // middle five numbers in below loop
  if (n % 2 == 0 || n % 3 == 0)
    return false;

  for (ll i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0)
      return false;

  return true;
}

struct parts {

  int start, en;
  // bool included;
};

struct c {

  ll num;
  ll type;
};

int checkFor(ll m, c arr[], int n) {
  f(i, 0, n) {
    if (arr[i].num == m)
      return i;
  }
}
void solve() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  vector<ll> b(m);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < m; i++)
    cin >> b[i];
  vector<ll> sumA(n + 1);
  vector<ll> sumB(m + 1);
  for (int i = 0; i < n; i++)
    sumA[i + 1] = sumA[i] + a[i];
  for (int i = 0; i < m; i++)
    sumB[i + 1] = sumB[i] + b[i];
  int total = 0;
  for (int i = 0; i <= n; i++) {
    ll other = k - sumA[i];
    if (other < 0)
      continue;
    int l = lower_bound(sumB.begin(), sumB.end(), other) - sumB.begin();
    if (l > m || sumB[l] > other)
      --l;
    //            cout<<other<<" "<<l<<" "<<i<<" "<<"\\n";
    total = max(total, i + l);
  }
  cout << total;
}

int main() {
  fastIO;

  tc solve();
}