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

//                   ********** YATIN KWATRA **********

// AC BAKSHI RABBA

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define endl "\\n"
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define rfo(i, a, b) for (int i = a; i >= b; i--)
#define vii vector<int>
#define vll vector<ll>
#define pq priority_queue
#define uom unordered_map
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define pob pop_back
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long, long>
#define mll map<ll, ll>
#define mii map<int, int>
#define vvii vector<vii>
#define vvll vector<vll>
#define mod 1000000007
#define pi 3.1415926535897932384626433832795
// #define node                    Node

using namespace std;

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

/*

   -> Check For Overflows
   -> Out of Bounds
   -> Initialisations of global arrays and variables
   -> Its not Always Complex, Try to simplify
   -> write it down and try to solve
   -> Have Faith in urself and in ur approach
   -> If it seems totally out of reach, switch to next :)
   -> And Come Back later, if possible
*/

const int N = 200005;
int v1[N];
int v2[N];

void solve() {
  int n, m;
  ll t;
  cin >> n >> m >> t;

  fo(i, 0, n - 1) cin >> v1[i];
  fo(i, 0, m - 1) cin >> v2[i];

  ll sum = 0LL;
  int best = 0;

  int i = -1;
  while ((i + 1) < n) {
    if (((sum + v1[i + 1]) <= t))
      sum += v1[++i];
    else
      break;
  }

  int j = -1;

  while ((j + 1) < m) {
    if (((sum + v2[j + 1]) <= t))
      sum += v2[++j];
    else
      break;
  }

  best = max(best, (i + j + 2));

  //  cout << i << ' ' << j << " " << best << endl;

  while ((j + 1) < m and i >= 0) {
    // cout << "Yes\\n";
    //  cout << " sum : " << sum << " i: " << i << " j: " << j << endl;

    sum -= v1[i--];

    while ((j + 1) < m) {
      if (((sum + v2[j + 1]) <= t))
        sum += v2[++j];
      else
        break;
    }

    best = max(best, (i + j + 2));
  }

  cout << best << endl;
}
int main() {

  FIO
      //  INPUT();

      int t;
  t = 1;
  //   cin >> t;

  while (t--) {
    solve();
  }
  return 0;
}


Error: 0

Fixed submission:

//                   ********** YATIN KWATRA **********

// AC BAKSHI RABBA

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define endl "\\n"
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define rfo(i, a, b) for (int i = a; i >= b; i--)
#define vii vector<int>
#define vll vector<ll>
#define pq priority_queue
#define uom unordered_map
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define pob pop_back
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long, long>
#define mll map<ll, ll>
#define mii map<int, int>
#define vvii vector<vii>
#define vvll vector<vll>
#define mod 1000000007
#define pi 3.1415926535897932384626433832795
// #define node                    Node

using namespace std;

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

/*

   -> Check For Overflows
   -> Out of Bounds
   -> Initialisations of global arrays and variables
   -> Its not Always Complex, Try to simplify
   -> write it down and try to solve
   -> Have Faith in urself and in ur approach
   -> If it seems totally out of reach, switch to next :)
   -> And Come Back later, if possible
*/

const int N = 100005;
int v1[N];
int v2[N];

void solve() {
  int n, m;
  ll t;
  cin >> n >> m >> t;

  fo(i, 0, n - 1) cin >> v1[i];
  fo(i, 0, m - 1) cin >> v2[i];

  ll sum = 0LL;
  int best = 0;

  int i = -1;
  while ((i + 1) < n) {
    if (((sum + v1[i + 1]) <= t))
      sum += v1[++i];
    else
      break;
  }

  int j = -1;

  while ((j + 1) < m) {
    if (((sum + v2[j + 1]) <= t))
      sum += v2[++j];
    else
      break;
  }

  best = max(best, (i + j + 2));

  //  cout << i << ' ' << j << " " << best << endl;

  while ((j + 1) < m and i >= 0) {
    // cout << "Yes\\n";
    //  cout << " sum : " << sum << " i: " << i << " j: " << j << endl;

    sum -= v1[i--];

    while ((j + 1) < m) {
      if (((sum + v2[j + 1]) <= t))
        sum += v2[++j];
      else
        break;
    }

    best = max(best, (i + j + 2));
  }

  cout << best << endl;
}
int main() {

  FIO
      //  INPUT();

      int t;
  t = 1;
  //    cin >> t;

  while (t--) {
    solve();
  }
  return 0;
}