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

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define pb push_back
#define ff first
#define ss second
#define ii insert
#define ld long double
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define ppb pop_back
#define nuenxfiu                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define input                                                                  \\
  freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#define TT                                                                     \\
  int testcases;                                                               \\
  cin >> testcases;                                                            \\
  while (testcases--)
#define mk make_pair
#define MAX ((int)2e9 + 17)
#define N 200005
#define mod ((int)1e9 + 7)
#define MOD 1000003
// int fact[1000007]={0};
int fpow(int n, int k, int p = mod) {
  int r = 1;
  while (k > 0) {
    if (k & 1)
      r = r * n % p;
    n = n * n % p;
    k = k >> 1;
  }
  return r;
}
int expo(int x, int y) {
  int res = 1;
  while (y) {
    if (y % 2)
      res = (res * x % mod) % mod;
    x = (x * x) % mod;
    y /= 2;
  }
  return res;
}
int sub(int a, int b) { return (a % mod - b % mod + mod) % mod; }
int mul(int a, int b) { return ((a % mod) * (b % mod) + mod) % mod; }
int inv(int x) { return expo(x, mod - 2); }
using namespace std;

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

  vector<int> v1(n + 1, 0);
  vector<int> v2(m + 1, 0);

  for (int i = 1; i <= n; i++) {
    cin >> v1[i];
    v1[i] += v1[i - 1];
  }

  for (int i = 1; i <= m; i++) {
    cin >> v2[i];
    v2[i] += v2[i - 1];
  }

  int ans = 0;

  int id = m;

  for (int i = 0; i <= n; i++) {
    if (v1[i] > k)
      break;

    while (v1[i] + v2[id] > k)
      id--;

    ans = max(ans, i + id);
  }

  cout << ans << endl;
}
signed main() {

  nuenxfiu
  // TT
  solve();
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define pb push_back
#define ff first
#define ss second
#define ii insert
#define ld long double
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define ppb pop_back
#define nuenxfiu                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define input                                                                  \\
  freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#define TT                                                                     \\
  int testcases;                                                               \\
  cin >> testcases;                                                            \\
  while (testcases--)
#define mk make_pair
#define MAX ((int)2e9 + 17)
#define N 200005
#define mod ((int)1e9 + 7)
#define MOD 1000003
// int fact[1000007]={0};
int fpow(int n, int k, int p = mod) {
  int r = 1;
  while (k > 0) {
    if (k & 1)
      r = r * n % p;
    n = n * n % p;
    k = k >> 1;
  }
  return r;
}
int expo(int x, int y) {
  int res = 1;
  while (y) {
    if (y % 2)
      res = (res * x % mod) % mod;
    x = (x * x) % mod;
    y /= 2;
  }
  return res;
}
int sub(int a, int b) { return (a % mod - b % mod + mod) % mod; }
int mul(int a, int b) { return ((a % mod) * (b % mod) + mod) % mod; }
int inv(int x) { return expo(x, mod - 2); }
using namespace std;

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

  vector<int> v1(n);
  vector<int> v2(m);

  for (int i = 0; i < n; i++)
    cin >> v1[i];

  for (int i = 0; i < m; i++)
    cin >> v2[i];

  int cnt = 0;

  while (k > 0) {
    if (v1[0] < v2[0]) {
      k -= v1[0];
      auto it = v1.begin();
      v1.erase(it);
    } else if (v2[0] <= v1[0]) {
      k -= v2[0];
      auto it = v2.begin();
      v2.erase(it);
    }
    if (k >= 0)
      cnt++;
    else
      break;
  }

  cout << cnt << endl;
}
signed main() {

  nuenxfiu
  // TT
  solve();
  return 0;
}