alexjercan/bugnet huggingface dataset:
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

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

  vector<ll> a(n), b(m), dpa(n + 1), dpb(m + 1);
  rep(i, n) {
    cin >> a.at(i);
    dpa.at(i + 1) = dpa.at(i) + a.at(i);
  }
  rep(i, m) {
    cin >> b.at(i);
    dpb.at(i + 1) = dpb.at(i) + b.at(i);
  }

  int ans = 0, j = m;

  rep(i, n + 1) {
    if (dpa.at(i) > k)
      break;
    while (dpb.at(j) > k - dpa.at(i)) {
      j--;
    }
    ans = max(ans, i + j);
  }

  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

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

  vector<ll> a(n), b(m);
  rep(i, n) { cin >> a.at(i); }
  rep(i, m) { cin >> b.at(i); }

  int ans = 0, ai = 0, bi = 0, t = 0;

  while (t < k) {
    if (ai >= n && bi >= m) {
      break;
    } else if (ai >= n || a.at(ai) > b.at(bi)) {
      if (k - t < b.at(bi))
        break;
      t += b.at(bi);
      bi++;
      ans++;
    } else {
      if (k - t < a.at(ai))
        break;
      t += a.at(ai);
      ai++;
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using ll = long long;
template <class T> using vt = vector<T>;
using vvi = vector<vt<int>>;

int main() {
  int n, m, k;
  cin >> n >> m >> k;

  vt<int> a(n), b(m);
  ll time = 0, ac = -1;
  int cnt = 0, cm;
  bool f = true;
  rep(i, n) {
    cin >> a[i];
    if (time + a[i] <= k && f) {
      time += a[i];
      ++cnt;
      ac = i;
    } else
      f = false;
  }
  rep(i, m) cin >> b[i];

  cm = cnt;
  rep(i, m) {
    time += b[i];
    ++cnt;
    if (time <= k)
      cm = max(cm, cnt);
    else {
      if (ac == -1)
        break;
      else {
        while (time > k) {
          if (ac == -1)
            break;
          time -= a[ac];
          --ac;
          --cnt;
        }
      }
    }
  }

  cout << cm << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using ll = long long;
template <class T> using vt = vector<T>;
using vvi = vector<vt<int>>;

int main() {
  int n, m, k;
  cin >> n >> m >> k;

  vt<int> a(n), b(m);
  ll time = 0, ac;
  int cnt = 0, cm;
  bool f = true;
  rep(i, n) {
    cin >> a[i];
    if (time + a[i] <= k) {
      time += a[i];
      ++cnt;
    } else if (time + a[i] > k && f) {
      ac = i - 1;
      f = false;
    }
  }
  rep(i, m) cin >> b[i];

  cm = cnt;
  rep(i, m) {
    time += b[i];
    ++cnt;
    if (ac == -1 && time > k) {
      --cnt;
      break;
    } else if (time > k) {
      time -= a[ac];
      --ac;
      --cnt;
    }

    cm = max(cm, cnt);
  }

  cout << cm << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int N, M;
  cin >> N >> M;
  ull K;
  cin >> K;
  vector<ull> A(N), B(M);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 0; i < M; i++)
    cin >> B[i];
  vector<ull> Asum(N + 1), Bsum(M + 1);
  Asum[0] = 0;
  Bsum[0] = 0;
  for (int i = 1; i < N + 1; i++) {
    Asum[i] = Asum[i - 1] + A[i - 1];
  }
  for (int i = 1; i < M + 1; i++) {
    Bsum[i] = Bsum[i - 1] + B[i - 1];
  }
  // for(ull a : Asum) cout << a << endl;
  // for(ull b : Bsum) cout << b << endl;
  int j = M;
  int max_c = 0;
  for (int i = 0; i < N + 1; i++) {
    if (Asum[i] > K)
      break;
    for (; j >= 0; j--) {
      if (Asum[i] + Bsum[j] > K)
        continue;
      max_c = max(i + j, max_c);
      break;
    }
  }
  cout << max_c << endl;
}

Error: TLE

Fixed submission:

#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int N, M;
  cin >> N >> M;
  ull K;
  cin >> K;
  vector<ull> A(N), B(M);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 0; i < M; i++)
    cin >> B[i];
  vector<ull> Asum(N + 1), Bsum(M + 1);
  Asum[0] = 0;
  Bsum[0] = 0;
  for (int i = 1; i < N + 1; i++) {
    Asum[i] = Asum[i - 1] + A[i - 1];
  }
  for (int i = 1; i < M + 1; i++) {
    Bsum[i] = Bsum[i - 1] + B[i - 1];
  }
  // for(ull a : Asum) cout << a << endl;
  // for(ull b : Bsum) cout << b << endl;

  int max_c = 0;
  for (int i = 0; i < N + 1; i++) {
    if (Asum[i] > K)
      break;
    for (int j = 0; j < M + 1; j++) {
      if (Asum[i] + Bsum[j] <= K)
        max_c = max(i + j, max_c);
      else
        break;
    }
  }
  cout << max_c << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

ll n, m, k, a[200000], b[200000], pr[200001][2];

bool ok(int x) {
  for (int i = 0; i <= x; ++i) {
    if (i > n)
      break;
    if (x - i > m)
      continue;
    if (pr[i][0] + pr[x - i][1] <= k)
      return 1;
  }
  return 0;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  cin >> n >> m >> k;
  for (int i = 0; i < n; ++i)
    cin >> a[i], pr[i + 1][0] = a[i];
  for (int i = 0; i < m; ++i)
    cin >> b[i], pr[i + 1][1] = b[i];
  for (int i = 1; i <= n; ++i)
    pr[i][0] += pr[i - 1][0];
  for (int i = 1; i <= m; ++i)
    pr[i][1] += pr[i - 1][1];
  int l = 0, r = n + m;
  while (l < r) {
    int mid = (l + r + 1) / 2;
    if (ok(mid))
      l = mid;
    else
      r = mid - 1;
  }
  cout << l;
  return 0;
}

/* stuff you should look for
 * int overflow, array bounds
 * special cases (n=1?)
 * do smth instead of nothing and stay organized
 * WRITE STUFF DOWN
 */


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

ll n, m, k, a[200000], b[200000], pr[200000][2];

bool ok(int x) {
  for (int i = x - m; i <= n; ++i)
    if (pr[i][0] + pr[x - i][1] <= k)
      return 1;
  return 0;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  cin >> n >> m >> k;
  for (int i = 0; i < n; ++i)
    cin >> a[i], pr[i + 1][0] = a[i];
  for (int i = 0; i < m; ++i)
    cin >> b[i], pr[i + 1][1] = b[i];
  for (int i = 1; i <= n; ++i)
    pr[i][0] += pr[i - 1][0];
  for (int i = 1; i <= m; ++i)
    pr[i][1] += pr[i - 1][1];
  int l = 0, r = n + m;
  while (l < r) {
    int mid = (l + r + 1) / 2;
    if (ok(mid))
      l = mid;
    else
      r = mid - 1;
  }
  cout << l;
  return 0;
}

/* stuff you should look for
 * int overflow, array bounds
 * special cases (n=1?)
 * do smth instead of nothing and stay organized
 * WRITE STUFF DOWN
 */
Problem p02623 (C++) — buggy submission, verdict: Runtime Error


#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/

#define pll pair<long long, long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define D(x) cerr << #x " = " << (x) << endl
#define vll vector<ll>
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);
#define endl '\\n'
using namespace std;
int main() {
  IOS
      // freopen("input.txt","r",stdin);
      // freopen("output.txt","w",stdout);
      // freopen("error.txt","w",stderr);
      ll n,
      m, k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  vector<ll> b(m);
  ll pb[m];
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  for (ll i = 0; i < m; i++)
    cin >> b[i];
  ll ans = 0;
  ll sum = 0;
  for (ll i = 0; i < m; i++) {
    sum += b[i];
    if (sum <= k) {
      ans = max(ans, i + 1);
    }
    pb[i] = sum;
  }
  sum = 0;
  for (ll i = 0; i < n; i++) {
    sum += a[i];
    ll rem = k - sum;
    if (rem >= 0) {
      ans = max(ans, i + 1);
    }
    if (rem <= 0)
      break;
    ll l = 0, r = m - 1;
    while (l <= r) {
      ll mid = (l + r) / 2;
      if (pb[mid] <= rem) {
        ans = max(ans, mid + 1 + i + 1);
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:


#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/

#define pll pair<long long, long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define D(x) cerr << #x " = " << (x) << endl
#define vll vector<ll>
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);
#define endl '\\n'
using namespace std;
int main() {
  IOS
      // freopen("input.txt","r",stdin);
      // freopen("output.txt","w",stdout);
      // freopen("error.txt","w",stderr);
      ll n,
      m, k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  vector<ll> b(n);
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  for (ll i = 0; i < m; i++)
    cin >> b[i];
  ll aptr = 0, bptr = 0;
  ll ans = 0;
  while (aptr < n && bptr < m) {
    if (a[aptr] < b[bptr]) {
      if (k >= a[aptr]) {
        k -= a[aptr];
        aptr++;
        ++ans;
      } else {
        break;
      }
    } else {
      if (k >= b[bptr]) {
        k -= b[bptr];
        bptr++;
        ++ans;
      } else {
        break;
      }
    }
  }
  while (aptr < n) {
    if (k >= a[aptr]) {
      k -= a[aptr];
      aptr++;
      ++ans;
    } else {
      break;
    }
  }
  while (bptr < m) {
    if (k >= b[bptr]) {
      k -= b[bptr];
      bptr++;
      ++ans;
    } else {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int main() {
  long long N, M, K;
  cin >> N >> M >> K;

  vector<long long> A(N), AS(N + 1, 0), B(M), BS(M + 1, 0);

  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    AS[i + 1] = AS[i] + A[i];
  }
  for (int i = 0; i < M; ++i) {
    cin >> B[i];
    BS[i + 1] = BS[i] + B[i];
  }

  int an = 0, bn = 0, ans = 0;
  for (an = N; an >= 0; --an) {
    while (bn + 1 <= M && BS[bn + 1] <= K - AS[an])
      ++bn;
    if (K >= AS[an] + BS[bn])
      ans = max(an + bn, ans);
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  long long N, M, K;
  cin >> N >> M >> K;

  vector<long long> A(N), AS(N + 1, 0), B(M), BS(M + 1, 0);

  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    AS[i + 1] = AS[i] + A[i];
  }
  for (int i = 0; i < M; ++i) {
    cin >> B[i];
    BS[i + 1] = BS[i] + B[i];
  }

  int an = 0, bn = 0, ans = 0;
  for (an = N; an >= 0; --an) {
    while (BS[bn + 1] <= K - AS[an])
      ++bn;
    if (K >= AS[an] + BS[bn])
      ans = max(an + bn, ans);
  }

  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
  ll n, m, k;
  cin >> n >> m >> k;

  vector<ll> a(n);
  vector<ll> a_acc(n + 1, 0);
  vector<ll> b(m);
  vector<ll> b_acc(m + 1, 0);
  rep(i, n) {
    cin >> a[i];
    a_acc[i + 1] = a[i] + a_acc[i];
  }
  rep(i, m) {
    cin >> b[i];
    b_acc[i + 1] = b[i] + b_acc[i];
  }

  ll max_cnt = 0;
  rep(i, n + 1) {
    if (a_acc[i] > k) {
      break;
    }
    auto it = upper_bound(b_acc.begin(), b_acc.end(), (k - a_acc[i]));
    ll j = it - b_acc.begin();
    max_cnt = max(max_cnt, i + j - 1);
  }

  cout << max_cnt << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
  ll n, m, k;
  cin >> n >> m >> k;

  vector<ll> a(n);
  vector<ll> a_acc(n + 1, 0);
  vector<ll> b(m);
  vector<ll> b_acc(m + 1, 0);
  rep(i, n) {
    cin >> a[i];
    a_acc[i + 1] = a[i] + a_acc[i];
  }
  rep(i, m) {
    cin >> b[i];
    b_acc[i + 1] = b[i] + b_acc[i];
  }

  ll max_cnt = 0;
  rep(i, n + 1) {
    ll j = m;
    if (a_acc[i] > k) {
      break;
    }
    while ((a_acc[i] + b_acc[j]) > k) {
      j--;
    }
    max_cnt = max(max_cnt, i + j);
  }

  cout << max_cnt << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(void) {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  vector<ll> b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  vector<ll> va(n + 1);
  vector<ll> vb(m + 1);
  ll now = 0;
  rep(j, m) {
    vb[j] = now;
    now += b[j];
  }
  vb[m] = now;
  now = 0LL;
  rep(i, n) {
    va[i] = now;
    now += a[i];
  }
  va[n] = now;
  ll ans = 0;
  rep(i, m + 1) {
    ll tmp = k - vb[i];
    if (tmp < 0)
      break;
    if (tmp > va[va.size() - 1])
      continue;
    auto itr = upper_bound(va.begin(), va.end(), tmp);
    ll p = (ll)(itr - va.begin()) - (ll)1 + (ll)i;
    ans = max(p, ans);
  }
  cout << ans << endl;
  return 0;
}

Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(void) {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  vector<ll> va(n + 1);
  vector<ll> vb(m + 1);
  ll now = 0;
  rep(j, m) {
    vb[j] = now;
    now += b[j];
  }
  vb[m] = now;
  now = 0LL;
  rep(i, n) {
    va[i] = now;
    now += a[i];
  }
  va[n] = now;
  ll ans = 0;
  rep(i, m + 1) {
    ll tmp = k - vb[i];
    if (tmp <= 0)
      break;
    if (tmp > va[va.size() - 1])
      continue;
    auto itr = upper_bound(va.begin(), va.end(), tmp);
    ll p = (ll)(itr - va.begin()) - (ll)1 + (ll)i;
    ans = max(p, ans);
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <bits/stdc++.h>
using namespace std;

vector<long long int> all1;

int solve(long long int number) {
  int siz = all1.size() - 1;
  int i = 0, j = siz;
  while (i < j) {

    int mid = i + (j - i) / 2;
    if (all1[mid] == number)
      return mid;

    else if (all1[mid] > number) {
      j = mid - 1;
    } else
      i = mid;

    cout << i << " " << j << endl;
  }

  return i;
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  long long int a, b, c;
  cin >> a >> b >> c;
  vector<long long int> all;
  all.push_back(0);
  all1.push_back(0);

  for (int i = 1; i <= a; i++) {
    int first;
    cin >> first;
    all.push_back(first + all[i - 1]);
  }
  for (int i = 1; i <= b; i++) {
    int first;
    cin >> first;
    all1.push_back(first + all1[i - 1]);
  }

  /* for(int i=0;i<a;i++)
   {
     cout<<all[i]<<" "<<all1[i]<<endl;
   }*/

  int count = 0;
  for (int i = 0; i <= a; i++) {
    int temp = 0;
    if (c - all[i] >= 0) {
      int index =
          upper_bound(all1.begin(), all1.end(), c - all[i]) - all1.begin();
      temp = (i + index - 1);
      count = max(count, temp);
    } else
      break;
  }

  cout << count << endl;

  return 0;
}

Error: TLE

Fixed submission:


#include <bits/stdc++.h>
using namespace std;

vector<long long int> all1;

int solve(long long int number) {
  int siz = all1.size() - 1;
  int i = 0, j = siz;
  while (i < j) {

    int mid = i + (j - i) / 2;
    if (all1[mid] == number)
      return mid;

    else if (all1[mid] > number) {
      j = mid - 1;
    } else
      i = mid;

    // cout<<i<<" "<<j<<endl;
  }

  return i;
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  long long int a, b, c;
  cin >> a >> b >> c;
  vector<long long int> all;
  all.push_back(0);
  all1.push_back(0);

  for (int i = 1; i <= a; i++) {
    int first;
    cin >> first;
    all.push_back(first + all[i - 1]);
  }
  for (int i = 1; i <= b; i++) {
    int first;
    cin >> first;
    all1.push_back(first + all1[i - 1]);
  }

  /* for(int i=0;i<a;i++)
   {
     cout<<all[i]<<" "<<all1[i]<<endl;
   }*/

  int count = 0;
  for (int i = 0; i <= a; i++) {
    int temp = 0;
    if (c - all[i] >= 0) {
      int index = solve(c - all[i]);
      //  cout<<index<<endl;
      temp = (i + index);
      count = max(count, temp);
    } else
      break;
  }

  cout << count << endl;

  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(n) begin(n), end(n)
#define IN(a, x, b) (a <= x && x < b)
#define INIT                                                                   \\
  std::ios::sync_with_stdio(false);                                            \\
  std::cin.tie(0);
template <class T> inline T CHMAX(T &a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T> inline T CHMIN(T &a, const T b) {
  return a = (a > b) ? b : a;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main() {
  INIT;

  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  vector<int> b(m);
  REP(i, n) cin >> a[i];
  REP(i, m) cin >> b[i];

  ll t = 0;
  REP(i, m) t += b[i];

  int j = m;
  int ans = 0;
  REP(i, n + 1) {
    while (j > 0 && t > k) {
      --j;
      t -= b[j];
    }
    if (t > k)
      break;
    ans = max(ans, i + j);
    if (i == n)
      break;
    t += a[i];
  }
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(n) begin(n), end(n)
#define IN(a, x, b) (a <= x && x < b)
#define INIT                                                                   \\
  std::ios::sync_with_stdio(false);                                            \\
  std::cin.tie(0);
template <class T> inline T CHMAX(T &a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T> inline T CHMIN(T &a, const T b) {
  return a = (a > b) ? b : a;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int N, M, K;
int MAX = 0;
vector<int> A;
vector<int> B;

int dp(int ia, int ib, int k) {
  if (k < 0)
    return ia + ib - 1;
  if (ia == N and ib == M)
    return ia + ib;
  if (ia == N)
    return dp(ia, ib + 1, k - B[ib]);
  if (ib == M)
    return dp(ia + 1, ib, k - A[ia]);
  return max(dp(ia, ib + 1, k - B[ib]), dp(ia + 1, ib, k - A[ia]));
}

int main() {
  INIT;
  cin >> N >> M >> K;

  REP(i, N) {
    int ax;
    cin >> ax;
    A.push_back(ax);
  }
  REP(i, M) {
    int bx;
    cin >> bx;
    B.push_back(bx);
  }

  cout << dp(0, 0, K) << endl;

  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
using namespace std;
const long long INF = 1e9 + 7;
const string alp = "abcdefghijklmnopqrstuvwxyz"; // 26
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
// const ll MOD=998244353LL;
// const ll MOD=1777777777LL;

int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  ll a[N], b[M];
  ll sum = 0;
  ll sumsum = 0;
  ll counta = -1, countb = 0;
  ll ans = 0;
  rep(i, N) {
    cin >> a[i];
    if (sumsum + a[i] <= K) {
      sum += a[i];
      ans++;
      counta = i;
    }
    sumsum += a[i];
  }
  sumsum = sum;

  rep(i, M) {
    cin >> b[i];
    if (sumsum + b[i] <= K) {
      sum += b[i];
      ans++;
      countb++;
    }
    sumsum += b[i];
  }
  ll ma = ans;
  for (int i = counta; i >= 0; i--) {
    sum -= a[i];
    ans--;
    while (sum + b[countb] <= K && countb < M) {
      sum += b[countb];
      countb++;
      ans++;
    }
    ma = max(ma, ans);
  }
  cout << ma << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
using namespace std;
const long long INF = 1e9 + 7;
const string alp = "abcdefghijklmnopqrstuvwxyz"; // 26
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
// const ll MOD=998244353LL;
// const ll MOD=1777777777LL;

int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  queue<ll> a;
  queue<ll> b;
  rep(i, N) {
    ll aa;
    cin >> aa;
    a.push(aa);
  }
  rep(i, M) {
    ll bb;
    cin >> bb;
    b.push(bb);
  }
  ll ans = 0;
  ll sum = 0;
  while (!a.empty() || !b.empty()) {
    if (a.empty() && sum + b.front() <= K) {
      ans++;
      sum += b.front();
      b.pop();
    } else if (b.empty() && sum + a.front() <= K) {
      ans++;
      sum += a.front();
      a.pop();
    } else if (sum + min(a.front(), b.front()) <= K) {
      if (a.front() >= b.front()) {
        ans++;
        sum += b.front();
        b.pop();
      } else {
        ans++;
        sum += a.front();
        a.pop();
      }
    } else {
      break;
    }
  }
  cout << ans << endl;
}