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

#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i, a, b) for (int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _                                                                      \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\\n'
using namespace std;
typedef double ld;
typedef long long lli;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define deb(x) cout << #x ": " << (x) << endl;

const int N = 61;
const lli INF = 1e18;
const lli MOD = 13;
const double EPS = 1e-4;

bool m[N];
vi primes(1, 2);
void sieve() {
  for (int i = 4; i < N; i += 2)
    m[i] = 1;
  for (int i = 3; i * i <= N; i += 2)
    if (!m[i])
      for (int j = i * i; j < N; j += i)
        m[j] = 1;
  for (int i = 3; i < N; i += 2)
    if (!m[i])
      primes.pb(i);
}

lli gcd(lli a, lli b) { return (b ? gcd(b, a % b) : a); }

lli lcm(lli a, lli b) {
  if (a < b)
    swap(a, b);
  lli c = gcd(a, b);
  a /= c;
  return a * b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b) {
  lli res = 1;
  while (b) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b /= 2;
  }
  return res;
}

lli powm(lli a, lli b) {
  lli res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % MOD;
    a = (a * a) % MOD;
    b /= 2;
  }
  return res;
}

bool isPrime(lli x) {
  if (x == 1)
    return 0;
  for (auto i : primes) {
    if (i * i > x)
      return 1;
    if (x % i == 0)
      return 0;
  }
  return 1;
}

// ---- コーディングはここから！ ('-')7

int main() {
  _ lli a, b, d;
  cin >> a >> b >> d;
  vl u(a), v(b);
  fore(i, 0, a) cin >> u[i];
  fore(i, 0, b) cin >> v[i];
  vl s1(1, 0), s2(1, 0);
  fore(i, 0, a) {
    if (s1.back() + u[i] <= d)
      s1.pb(s1.back() + u[i]);
    else
      break;
  }
  fore(i, 0, b) {
    if (s2.back() + v[i] <= d)
      s2.pb(s2.back() + v[i]);
    else
      break;
  }
  int mx = 0;
  fore(i, 0, sz(s1)) {
    int x = upper_bound(all(s2), d - s1[i]) - s2.begin();
    if (x > 0)
      x--;
    mx = max(mx, x + i);
  }
  fore(i, 0, sz(s2)) {
    int x = upper_bound(all(s1), d - s2[i]) - s1.begin();
    if (x > 0)
      x--;
    mx = max(mx, x + i);
  }
  cout << mx << ENDL;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i, a, b) for (int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _                                                                      \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\\n'
using namespace std;
typedef double ld;
typedef long long lli;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define deb(x) cout << #x ": " << (x) << endl;

const int N = 61;
const lli INF = 1e14;
const lli MOD = 13;
const double EPS = 1e-4;

bool m[N];
vi primes(1, 2);
void sieve() {
  for (int i = 4; i < N; i += 2)
    m[i] = 1;
  for (int i = 3; i * i <= N; i += 2)
    if (!m[i])
      for (int j = i * i; j < N; j += i)
        m[j] = 1;
  for (int i = 3; i < N; i += 2)
    if (!m[i])
      primes.pb(i);
}

lli gcd(lli a, lli b) { return (b ? gcd(b, a % b) : a); }

lli lcm(lli a, lli b) {
  if (a < b)
    swap(a, b);
  lli c = gcd(a, b);
  a /= c;
  return a * b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b) {
  lli res = 1;
  while (b) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b /= 2;
  }
  return res;
}

lli powm(lli a, lli b) {
  lli res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % MOD;
    a = (a * a) % MOD;
    b /= 2;
  }
  return res;
}

bool isPrime(lli x) {
  if (x == 1)
    return 0;
  for (auto i : primes) {
    if (i * i > x)
      return 1;
    if (x % i == 0)
      return 0;
  }
  return 1;
}

// ---- コーディングはここから！ ('-')7

int main() {
  _ lli a, b, d;
  cin >> a >> b >> d;
  vl u(max(a, b), INF), v(max(a, b), INF);
  fore(i, 0, a) cin >> u[i];
  fore(i, 0, b) cin >> v[i];
  lli sum = 0, i = 0;
  while (1) {
    lli x = min(u[i], v[i]);
    if (sum + x <= d) {
      sum += x;
      i++;
    } else
      break;
  }
  cout << i << ENDL;
}