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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(1e9 + 7);
const double pi = acos(-1);
#define rep0(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define rrep0(i, n) for (ll(i) = (n)-1; (i) >= 0; --(i))
#define rep1(i, n) for (ll(i) = 1; (i) <= (n); ++(i))
#define rrep1(i, n) for (ll(i) = (n); (i) >= 1; --(i))
#define nfor(i, a, b) for (ll(i) = (a); (i) < (b); ++(i))
#define rnfor(i, a, b) for (ll(i) = (b)-1; (i) >= (a); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(), (x).end()
#define yes pf("Yes")
#define no pf("No")
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

ll factorial(ll n) {
  ll ans = 1;
  rep1(i, n) {
    ans *= i;
    ans %= mod;
  }
  return ans;
}

ll power(ll a, ll b) {
  ll ans = 1;
  a %= mod;
  while (b) {
    if (b & 1LL)
      ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans % mod;
}

vector<ll> FactorialInv, Factorial;

void init_combination(ll MAX) {
  Factorial.resize(MAX + 1);
  FactorialInv.resize(MAX + 1);
  Factorial[0] = 1;
  for (int i = 1; i <= MAX; i++) {
    Factorial[i] = Factorial[i - 1] * i % mod;
  }
  FactorialInv[MAX] = power(Factorial[MAX], mod - 2);
  for (ll i = MAX - 1; i >= 0; i--) {
    FactorialInv[i] = FactorialInv[i + 1] * (i + 1) % mod;
  }
}

ll combination(ll a, ll b) {
  if ((a == b) || (b == 0)) {
    return 1;
  }
  if (a < b)
    return 0;
  if (b < 0)
    return 0;
  ll ans = Factorial[a] * FactorialInv[b] % mod;
  ans = ans * FactorialInv[a - b] % mod;
  return ans;
}

// modの値の確認をすること
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vl a(n + 2, 0), b(m + 2, 0);
  rep1(i, n) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  rep1(i, m) {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  a[n + 1] = INF;
  b[m + 1] = INF;
  ll ans = 0;
  rep0(i, n + 2) if (a[i] <= k)
      chmax(ans, ll(i + (upper_bound(all(b), k - a[i]) - b.begin()) - 1));
  pf(ans);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(1e9 + 7);
const double pi = acos(-1);
#define rep0(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define rrep0(i, n) for (ll(i) = (n)-1; (i) >= 0; --(i))
#define rep1(i, n) for (ll(i) = 1; (i) <= (n); ++(i))
#define rrep1(i, n) for (ll(i) = (n); (i) >= 1; --(i))
#define nfor(i, a, b) for (ll(i) = (a); (i) < (b); ++(i))
#define rnfor(i, a, b) for (ll(i) = (b)-1; (i) >= (a); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(), (x).end()
#define yes pf("Yes")
#define no pf("No")
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

ll factorial(ll n) {
  ll ans = 1;
  rep1(i, n) {
    ans *= i;
    ans %= mod;
  }
  return ans;
}

ll power(ll a, ll b) {
  ll ans = 1;
  a %= mod;
  while (b) {
    if (b & 1LL)
      ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans % mod;
}

vector<ll> FactorialInv, Factorial;

void init_combination(ll MAX) {
  Factorial.resize(MAX + 1);
  FactorialInv.resize(MAX + 1);
  Factorial[0] = 1;
  for (int i = 1; i <= MAX; i++) {
    Factorial[i] = Factorial[i - 1] * i % mod;
  }
  FactorialInv[MAX] = power(Factorial[MAX], mod - 2);
  for (ll i = MAX - 1; i >= 0; i--) {
    FactorialInv[i] = FactorialInv[i + 1] * (i + 1) % mod;
  }
}

ll combination(ll a, ll b) {
  if ((a == b) || (b == 0)) {
    return 1;
  }
  if (a < b)
    return 0;
  if (b < 0)
    return 0;
  ll ans = Factorial[a] * FactorialInv[b] % mod;
  ans = ans * FactorialInv[a - b] % mod;
  return ans;
}

// modの値の確認をすること
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vl a(n + 2, 0), b(m + 2, 0);
  rep1(i, n) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  rep1(i, m) {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  a[n + 1] = INF;
  b[n + 1] = INF;
  ll ans = 0;
  rep0(i, n) if (a[i] < k)
      chmax(ans, ll(i + (lower_bound(all(b), k - a[i]) - b.begin() - 1)));
  pf(ans);
  return 0;
}