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

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define rept(i, m, n) for (ll i = m; i < n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V)                                                               \\
  for (auto v : (V))                                                           \\
  cout << v << " "
// charを整数に
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];
void cum_sum(int N, vector<ll> a, vector<ll> &s) {
  for (int i = 0; i < N; i++) {
    s[i + 1] = s[i] + a[i];
  }
}
// ユークリッドの控除法
ll gcd(ll a, ll 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; // Be careful not to overflow
}
// 素数判定
bool is_prime(long long n) {
  if (n <= 1)
    return false;
  for (long long p = 2; p * p <= n; ++p) {
    if (n % p == 0)
      return false;
  }
  return true;
}
int getdigit(ll num) {
  unsigned digit = 0;
  while (num != 0) {
    num /= 10;
    digit++;
  }
  return digit;
}
// 空白文字も入力 getline(cin, S);
// 桁数指定 setprecision

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll N, M, K;
  cin >> N >> M >> K;
  VLL A(N), B(M);
  rep(i, N) { cin >> A[i]; }
  rep(i, M) { cin >> B[i]; }
  VLL s(N + 1);
  VLL t(M + 1);
  cum_sum(N, A, s);
  cum_sum(M, B, t);
  ll ans = 0;
  rep(i, N + 1) {
    ll tmp_ans = 0;
    ll tmp_K = K;
    ll sum = s[i];
    ll dif = tmp_K - sum;
    if (dif < 0)
      continue;
    if (dif == 0) {
      tmp_ans = i;
      ans = max(ans, tmp_ans);
      continue;
    }
    tmp_ans = i;
    auto it = upper_bound(t.begin(), t.end(), dif);
    tmp_ans += it - t.begin() - 1;
    ans = max(ans, tmp_ans);
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define rept(i, m, n) for (ll i = m; i < n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V)                                                               \\
  for (auto v : (V))                                                           \\
  cout << v << " "
// charを整数に
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];
void cum_sum(int N, vector<double> a, vector<double> &s) {
  for (int i = 0; i < N; i++) {
    s[i + 1] = s[i] + a[i];
  }
}
// ユークリッドの控除法
ll gcd(ll a, ll 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; // Be careful not to overflow
}
// 素数判定
bool is_prime(long long n) {
  if (n <= 1)
    return false;
  for (long long p = 2; p * p <= n; ++p) {
    if (n % p == 0)
      return false;
  }
  return true;
}
int getdigit(ll num) {
  unsigned digit = 0;
  while (num != 0) {
    num /= 10;
    digit++;
  }
  return digit;
}
// 空白文字も入力 getline(cin, S);
// 桁数指定 setprecision

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll N, M, K;
  cin >> N >> M >> K;
  VLL A(N);
  VLL B(M);
  ll a_sum = 0;
  ll b_sum = 0;
  ll mini = INF;
  rep(i, N) {
    cin >> A[i];
    a_sum += A[i];
    mini = min(mini, A[i]);
  }
  rep(i, M) {
    cin >> B[i];
    b_sum += B[i];
    mini = min(mini, A[i]);
  }
  if (K < mini) {
    cout << 0 << endl;
    return 0;
  }
  if (a_sum + b_sum <= K) {
    cout << N + M << endl;
    return 0;
  }
  ll count_a = 0;
  ll count_b = 0;
  ll ans = 0;
  ll time = 0;
  while (1) {
    ll tmp_a, tmp_b;
    if (count_a < N) {
      tmp_a = A[count_a];
    } else {
      tmp_a = INF;
    }
    if (count_b < M) {
      tmp_b = B[count_b];
    } else {
      tmp_b = INF;
    }
    if (tmp_a <= tmp_b) {
      time += tmp_a;
      if (time > K)
        break;
      count_a++;
      ans++;
    } else {
      time += tmp_b;
      if (time > K)
        break;
      count_b++;
      ans++;
    }
    if (count_a >= N && count_b >= M)
      break;
  }
  cout << ans << endl;
}