alexjercan/bugnet huggingface dataset:
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, n) for (int i = 0; i <= (n); i++)
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define FORS(i, a, b) for (int i = a; i <= (b); i++)
// for container x
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
#pragma endregion

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1, 0);
  vector<ll> b(m + 1, 0);
  int a_max = n;
  FORS(i, 1, n) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  FORS(i, 1, m) {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  int ans = 0;
  REPS(a_read, n) {
    if (a[a_read] > k)
      continue;
    else {
      // decltype(b)::iterator itr;
      // if (a_read==a_max) itr = upper_bound(ALL(b), k-a[a_max]);
      // else itr = upper_bound(ALL(b), a[a_read+1]-a[a_read]);
      auto itr = upper_bound(ALL(b), k - a[a_read]);
      int b_read = (itr - b.begin()) - 1;
      ans = max(ans, a_read + b_read);
    }
  }
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long ll;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, n) for (int i = 0; i <= (n); i++)
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define FORS(i, a, b) for (int i = a; i <= (b); i++)
// for container x
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
#pragma endregion

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1, 0);
  vector<ll> b(m + 1, 0);
  int a_max = n + 1;
  int b_max = m + 1;
  FORS(i, 1, n) {
    cin >> a[i];
    a[i] += a[i - 1];
    if (a[i] > k)
      a_max = min(i, a_max);
  }
  FORS(i, 1, m) {
    cin >> b[i];
    b[i] += b[i - 1];
    if (b[i] > k)
      b_max = min(i, b_max);
  }
  ll ans = 0;
  ll read = 0;
  REP(i, a_max) {
    read = i;
    FOR(j, 1, b_max) if (a[i] + b[j] <= k) read++;
    else break;
    ans = max(ans, read);
  }
  cout << ans << endl;

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

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define pll pair<long long, long long>
using namespace std;
using ll = long long;
using ld = long double;

// グローバル変数（入力）
ll n, m, k;
vll a, b;

void input() {
  cin >> n >> m >> k;
  a.resize(n);
  rep(i, n) { cin >> a[i]; }
  b.resize(m);
  rep(i, m) { cin >> b[i]; }
}

void solve() {
  // 累積わ
  vll ra(n + 1);
  vll rb(m + 1);
  ra[0] = 0;
  rb[0] = 0;
  rep1(i, n) { ra[i] = ra[i - 1] + a[i - 1]; }
  rep1(i, m) { rb[i] = rb[i - 1] + b[i - 1]; }
  ll ans = 0, j = m;
  rep(i, n + 1) {
    if (ra[i] > k) {
      break;
    }
    while (ra[i] + rb[j] > k) {
      j--;
    }
    ans = max(ans, i + j);
  }
  cout << ans << endl;
}

int main() {
  input();
  solve();
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define pll pair<long long, long long>
using namespace std;
using ll = long long;
using ld = long double;

// グローバル変数（入力）
ll n, m, k;
vll a, b;

void input() {
  cin >> n >> m >> k;
  a.resize(n);
  rep(i, n) { cin >> a[i]; }
  b.resize(m);
  rep(i, m) { cin >> b[i]; }
}

void solve() {
  // 累積わ
  vll ra(n);
  vll rb(m);
  ra[0] = a[0];
  rb[0] = b[0];
  ll newn = n, newm = m;
  rep1(i, n) {
    ra[i] = ra[i - 1] + a[i];
    if (ra[i] > k) {
      newn = i;
      break;
    }
  }
  rep1(i, m) {
    rb[i] = rb[i - 1] + b[i];
    if (rb[i] > k) {
      newm = i;
      break;
    }
  }
  ll ans = 0;
  if (a[0] <= k || b[0] <= k) {
    ans = 1;
  }
  rep(i, newn) {
    rep(j, newm) {
      if (ra[i] + rb[j] <= k) {
        ans = max(ans, i + j + 2);
      } else {
        break;
      }
    }
  }
  cout << ans << endl;
}

int main() {
  input();
  solve();
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define PI 3.14159265358979323846264338327950L

vector<long long> A, B;
long long K;

int main(void) {

  long long N, M, tmp, ans = 0, time = 0, total = 0, b_max;

  cin >> N >> M >> K;

  vector<long long> A_sum(N + 1, 0), B_sum(M + 1, 0);

  A_sum.push_back(0);
  for (long long i = 1; i <= N; i++) {
    cin >> tmp;
    A.push_back(tmp);
    A_sum[i] = A_sum[i - 1] + tmp;
  }

  B_sum.push_back(0);
  for (long long i = 1; i <= M; i++) {
    cin >> tmp;
    B.push_back(tmp);
    B_sum[i] = B_sum[i - 1] + tmp;
  }

  ans = 0;
  long long tmp_m = M;
  for (long long i = 0; i <= N; i++) {
    for (long long j = tmp_m; j >= 0; j--) {
      if (A_sum[i] + B_sum[j] <= K) {
        if (ans < i + j) {
          ans = i + j;
        }
        tmp_m = j;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int a, b, t;
  cin >> a >> b >> t;
  vector<int> A, B, Asum, Bsum;
  Asum.push_back(0);
  Bsum.push_back(0);
  for (int i = 1; i <= a; ++i) {
    int tmp;
    cin >> tmp;
    A.push_back(tmp);
    Asum[i] = Asum[i - 1] + tmp;
  }
  for (int i = 1; i <= b; ++i) {
    int tmp;
    cin >> tmp;
    B.push_back(tmp);
    Bsum[i] = Bsum[i - 1] + tmp;
  }
  int dem = 0;
  for (int i = 1; i <= a; ++i) {
    for (int j = 1; j <= b; ++j) {
      if (Asum[i] + Bsum[j] > t) {
        break;
      } else {
        if (dem < i + j)
          dem = i + j;
      }
    }
  }
  cout << dem;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

using ll = long long int;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()

#define pi 3.14159265358979323846

template <class T> bool ch1000000(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;
}

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

  vector<ll> A(N + 1), B(M + 1);
  A[0] = 0;
  B[0] = 0;

  for (ll i = 1; i <= N; i++) {
    ll Ai;
    cin >> Ai;
    A[i] = Ai + A[i - 1];
  }
  for (ll i = 1; i <= M; i++) {
    ll Bi;
    cin >> Bi;
    B[i] = Bi + B[i - 1];
  }

  ll ia = 0;
  for (ll i = 1; i <= N; i++) {
    if (A[i] <= K) {
      ia = i;
    } else {
      break;
    }
  }
  ll ib = 0;
  for (ll i = 1; i <= M; i++) {
    if (A[ia] + B[i] <= K) {
      ib = i;
    } else {
      break;
    }
  }

  ll ans = ia + ib;

  for (ll i = ia; i >= 0; i--) {
    for (ll j = ib; j <= M; j++) {
      if (A[i] + B[j] <= K) {
        ans = max(ans, i + j);
      } else {
        ib = j;
        break;
      }
    }
  }

  cout << ans << endl;

  // cout << setprecision(8) << ans << endl;  // For double
}


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

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

using ll = long long int;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()

#define pi 3.14159265358979323846

template <class T> bool ch1000000(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;
}

int main() {

  ll N, M, K;

  cin >> N >> M >> K;

  vector<ll> A(N), B(M);

  ll ia = 0, ib = 0, ans = 0;
  A[0] = 0;
  B[0] = 0;
  for (ll i = 1; i <= N; i++) {
    cin >> A[i];
    A[i] += A[i - 1];
  }
  for (ll i = 1; i <= M; i++) {
    cin >> B[i];
    B[i] += B[i - 1];
  }

  // for(ll i = 1; i <= N; i++){
  //   if(A[i] <= K){
  //     ia = i;
  //   }else{
  //     break;
  //   }
  // }

  // for(ll i = 1; i <= M; i++){
  //   if(A[ia] + B[i] <= K){
  //     ib = i;
  //   }else{
  //     break;
  //   }
  // }

  ans = ia + ib;

  // for(ll i = ia-1; i >= 0; i--){
  //   for(ll j = ib+1; j <= M; j++){
  //     if(A[i-1] + B[j] <= K){
  //       if(ans < i + j) ans = i + j;
  //     }else{
  //       ib = j-1;
  //       break;
  //     }
  //     if(j == M){
  //       cout << ans << endl;
  //       return 0;
  //     }
  //   }
  // }

  cout << ans << endl;

  // cout << setprecision(8) << ans << endl;  // For double
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P, int>
#define T tuple<int, int, int>
using namespace std;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  ll ans = 0;
  ll asatu = 0;
  ll bsatu = 0;
  ll tmp = 0;
  int aindex = 0;
  int bindex = 0;
  rep(i, n) {
    if (tmp + a[i] <= k) {
      tmp += a[i];
      ans++;
      asatu++;
      aindex++;
    } else
      break;
  }
  aindex--;
  while (asatu >= 0) {
    while (tmp + b[bindex] <= k && bindex < b.size()) {
      tmp += b[bindex];
      bindex++;
      bsatu++;
    }
    ans = max(ans, asatu + bsatu);
    if (aindex >= 0)
      tmp -= a[aindex];
    aindex--;
    asatu--;
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P, int>
#define T tuple<int, int, int>
using namespace std;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  ll ans = 0;
  ll asatu = 0;
  ll bsatu = 0;
  ll tmp = 0;
  int aindex = 0;
  int bindex = 0;
  rep(i, n) {
    if (tmp + a[i] <= k) {
      tmp += a[i];
      ans++;
      asatu++;
      aindex++;
    } else
      break;
  }
  bool first = true;
  while (asatu > 0 || first == true) {
    first = false;
    while (tmp + b[bindex] <= k) {
      tmp += b[bindex];
      bindex++;
      bsatu++;
    }
    ans = max(ans, asatu + bsatu);
    tmp -= a[aindex];
    aindex--;
    asatu--;
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m, k;
  cin >> n >> m >> k;

  vector<ll> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  vector<ll> sa(n + 1, 0);
  vector<ll> sb(m + 1, 0);
  rep(i, n) { sa[i + 1] = sa[i] + a[i]; }
  rep(i, m) { sb[i + 1] = sb[i] + b[i]; }
  ll ans = 0;
  rep(i, n + 1) {
    ll t = k - sa[i];
    if (t >= 0) {
      auto it = upper_bound(sb.begin(), sb.end(), t);
      int j = distance(sb.begin(), it) - 1;
      ll num = (ll)(i) + (ll)(j);
      ans = max(ans, num);
    }
  }
  cout << ans << endl;
  return 0;
}

Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <bits/stdc++.h>

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m, k;
  cin >> n >> m >> k;

  vector<ll> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  vector<ll> sa(n, 0);
  vector<ll> sb(m, 0);
  sa[0] = a[0];
  sb[0] = b[0];
  rep(i, n) { sa[i + 1] = sa[i] + a[i]; }
  rep(i, m) { sb[i + 1] = sb[i] + b[i]; }
  ll ans = 0;
  rep(i, n) {
    ll t = k - sa[i];
    if (t >= 0) {
      auto it = upper_bound(sb.begin(), sb.end(), t);
      int j = distance(sb.begin(), it) - 1;
      ll num = (i + 1) + (j + 1);
      ans = max(ans, num);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <fstream>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n, m, k, c;
  cin >> n >> m >> k;
  vector<long int> a(n + 1);
  vector<long int> b(m + 1);
  a[0] = b[0] = 0;
  rep(i, n) {
    cin >> a[i + 1];
    a[i + 1] += a[i];
  }
  rep(i, m) {
    cin >> b[i + 1];
    b[i + 1] += b[i];
  }
  int ans = 0, j = 0;
  rep(i, n + 1) {
    if (k - a[i] < 0)
      break;
    while (b[j] <= k - a[i]) {
      j++;
      if (j == m + 1)
        break;
    }
    j--;
    // cout<< j << " i " << i << endl;
    ans = max(ans, i + j);
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <fstream>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  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];
  int max_a = 0;
  int k_save = k;
  while (k >= 0) {
    k -= a[max_a];
    max_a++;
    if (max_a == n + 1)
      break;
  }
  max_a--;
  k = k_save;
  int books = 0, b_books = 0, ans = 0;
  rep(i, max_a + 1) {
    k -= accumulate(a.begin(), a.begin() + i, 0);
    while (k >= 0) {
      k -= b[b_books];
      b_books++;
      if (b_books == m + 1)
        break;
    }
    b_books--;
    books = i + b_books;
    if (ans < books)
      ans = books;
    k = k_save;
    b_books = 0;
    books = 0;
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);

void Main() {
  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 a(N + 2), b(M + 2);
  a[0] = 0, b[0] = 0;
  for (ll i = 0; i < N; i++)
    a[i + 1] = a[i] + A[i];
  for (ll i = 0; i < M; i++)
    b[i + 1] = b[i] + B[i];
  a[N + 1] = 3000000000;
  b[M + 1] = 3000000000;

  // for (ll i = 0; i < N+1; i++) cout << a[i] << " ";
  // cout << endl;
  // for (ll i = 0; i < M+1; i++) cout << b[i] << " ";
  // cout << endl;

  ll i = distance(a.begin(), upper_bound(a.begin(), a.end(), K)) - 1;
  ll j = distance(b.begin(), upper_bound(b.begin(), b.end(), K - a[i])) - 1;

  // cout << i << j << endl;

  ll ans = 0;
  for (; i >= 0; i--)
    for (; j <= M; j++) {
      if (a[i] + b[j] > K)
        break;
      if (ans < i + j)
        ans = i + j;
    }

  cout << ans << endl;
}

int main(int argc, char const *argv[]) {
  Main();
  return 0;
}

void yesno(bool state) {
  if (state)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);

void Main() {
  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 a(N + 2), b(M + 2);
  a[0] = 0, b[0] = 0;
  for (ll i = 0; i < N; i++)
    a[i + 1] = a[i] + A[i];
  for (ll i = 0; i < M; i++)
    b[i + 1] = b[i] + B[i];
  a[N + 1] = INFINITY;
  b[M + 1] = INFINITY;

  // for (ll i = 0; i < N+1; i++) cout << a[i] << " ";
  // cout << endl;
  // for (ll i = 0; i < M+1; i++) cout << b[i] << " ";
  // cout << endl;

  ll i = distance(a.begin(), upper_bound(a.begin(), a.end(), K)) - 1;
  ll j = distance(b.begin(), upper_bound(b.begin(), b.end(), K - a[i])) - 1;

  // cout << i << j << endl;

  ll ans = 0;
  for (; i >= 0; i--)
    for (; j <= N; j++) {
      if (a[i] + b[j] > K)
        break;
      if (ans < i + j)
        ans = i + j;
    }

  cout << ans << endl;
}

int main(int argc, char const *argv[]) {
  Main();
  return 0;
}

void yesno(bool state) {
  if (state)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vector<long long> A(N), B(M), preA(N + 1), preB(M + 1);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    preA[i + 1] += A[i] + preA[i];
    // cout << preA[i+1] << " ";
  }
  // cout << endl;
  for (int i = 0; i < M; i++) {
    cin >> B[i];
    preB[i + 1] += B[i] + preB[i];
    // cout << preB[i+1] << " ";
  }
  int res = 0;
  int posB = M;
  for (int i = 0; i <= N; i++) {
    int lenB = K - preA[i];
    if (lenB < 0)
      break;
    while (posB >= 0 && preB[posB] > lenB) {
      posB--;
    }
    // cout <<i << " " << posB << endl;
    res = max(res, posB + i);
  }
  cout << res << endl;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vector<int> A(N), B(M), preA(N + 1), preB(M + 1);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    preA[i + 1] += A[i] + preA[i];
    // cout << preA[i+1] << " ";
  }
  // cout << endl;
  for (int i = 0; i < M; i++) {
    cin >> B[i];
    preB[i + 1] += B[i] + preB[i];
    // cout << preB[i+1] << " ";
  }
  int res = 0;
  int posB = M;
  for (int i = 0; i <= N; i++) {
    int lenB = K - preA[i];
    while (preB[posB] > lenB) {
      posB--;
    }
    res = max(res, posB + i);
  }
  cout << res << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define ull unsigned long long
#define ll long long
#define imei(...) "[ " << #__VA_ARGS__ << " = " << __VA_ARGS__ << " ] "

using namespace std;

void solve(int t) {
  int n;
  cin >> n;
}

vector<ll> a, b;
int n, m, k;
int main(int argc, char *argv[]) {
  int ans = 0;
  cin >> n >> m >> k;
  a.resize(n + 1, 0);
  b.resize(m + 1, 0);

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

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

  for (int i = 0, j = m; i <= n; i++) {
    if (a[i] > k)
      break;
    while (a[i] + b[j] > k)
      j--;
    ans = max(ans, i + j);
  }

  cout << ans;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define ull unsigned long long
#define ll long long
#define imei(...) "[ " << #__VA_ARGS__ << " = " << __VA_ARGS__ << " ] "

using namespace std;

void solve(int t) {
  int n;
  cin >> n;
}

vector<ll> a, b;
ll n, m, k;
int main(int argc, char *argv[]) {
  cin >> n >> m >> k;
  a.resize(n + 1);
  b.resize(m + 1);

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

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

  a[n] = b[m] = 1000100000;

  int i1 = 0, i2 = 0;
  int count = 0;
  while (1) {
    ll t1 = a[i1];
    ll t2 = b[i2];
    if (t1 > k && t2 > k)
      break;

    if (t1 < t2) {
      i1++;
      k -= t1;
    } else if (t1 > t2) {
      i2++;
      k -= t2;
    } else {
      int idx1 = i1 + 1, idx2 = i2 + 1;
      while (a[idx1] == a[idx2]) {
        idx1++;
        idx2++;
      }
      if (a[idx1] > a[idx2]) {
        i1++;
        k -= t1;
      } else {
        i2++;
        k -= t2;
      }
    }
    count++;
  }

  cout << count << endl;

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

#include <bits/stdc++.h>
#define int long long
#define FLASH                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define rep(i, begin, end)                                                     \\
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \\
       i != (end) - ((begin) > (end));                                         \\
       i += 1 - 2 * ((begin) >                                                 \\
                     (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) -->
                             // {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

signed main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> A(n);
  vector<int> B(m);
  rep(i, 0, n) cin >> A[i];
  rep(i, 0, m) cin >> B[i];
  vector<int> a(n + 1);
  vector<int> b(m + 1);
  a[0] = 0;
  rep(i, 0, n) a[i + 1] = a[i] + A[i];
  b[0] = 0;
  rep(i, 0, m) b[i + 1] = b[i] + B[i];
  int ans = 0;
  int j = m;
  // cout << "a";
  rep(i, 0, n + 1) {
    if (a[i] > k)
      break;
    while (b[j] > k - a[i])
      j--;
    // cout << i << " " << j << endl;
    ans = max(ans, i + j);
  }
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define FLASH                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define rep(i, begin, end)                                                     \\
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \\
       i != (end) - ((begin) > (end));                                         \\
       i += 1 - 2 * ((begin) >                                                 \\
                     (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) -->
                             // {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

signed main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> A(n);
  vector<int> B(m);
  rep(i, 0, n) cin >> A[i];
  rep(i, 0, m) cin >> B[i];
  vector<int> a(n + 1);
  vector<int> b(m + 1);
  a[0] = 0;
  rep(i, 0, n) a[i + 1] = a[i] + A[i];
  b[0] = 0;
  rep(i, 0, m) b[i + 1] = b[i] + B[i];
  int ans = 0;
  // int j = m;
  // cout << "a";
  rep(i, 0, n + 1) {
    int j = 0;
    if (a[i] > k)
      break;
    while (b[j] <= k - a[i])
      j++;
    // cout << i << " " << j << endl;
    ans = max(ans, i + j - 1);
  }
  cout << ans;
  return 0;
}