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

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n, m;
  long long k;
  long long a[200005];
  long long b[200005];
  vector<long long> asum;
  vector<long long> bsum;

  asum.push_back(0);
  bsum.push_back(0);

  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0) {
      asum.push_back(a[i]);
    } else {
      asum.push_back(asum[i] + a[i]);
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    if (i == 0) {
      bsum.push_back(b[i]);
    } else {
      bsum.push_back(bsum[i] + b[i]);
    }
  }

  if (k >= asum[n - 1] + bsum[m - 1]) {
    cout << n + m << endl;
  } else {
    long long ans = 0;
    long long res;
    for (int i = 0; i <= n; i++) {
      long long t = k - asum[i];
      if (t < 0) {
        res = 0;
      } else if (t == 0) {
        res = i;
      } else {
        auto iter = upper_bound(bsum.begin(), bsum.end(), t);
        long long x = iter - bsum.begin() - 1;
        res = x + i;
      }
      ans = max(res, ans);
    }
    cout << ans << endl;
  }
}


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 <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n, m;
  long long k;
  long long a[200005];
  long long b[200005];
  vector<long long> asum;
  vector<long long> bsum;

  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0) {
      asum.push_back(a[i]);
    } else {
      asum[i] = asum[i - 1] + a[i];
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    if (i == 0) {
      bsum.push_back(b[i]);
    } else {
      bsum[i] = bsum[i - 1] + b[i];
    }
  }

  if (k >= asum[n - 1] + bsum[m - 1]) {
    cout << n + m << endl;
  } else {
    long long ans = 0;
    long long res;
    for (int i = 0; i < n; i++) {
      long long t = k - asum[i];
      if (t < 0) {
        res = 0;
      } else if (t == 0) {
        res = i;
      } else {
        auto iter = upper_bound(bsum.begin(), bsum.end(), t);
        long long x = iter - bsum.begin();
        res = x + i;
      }
      ans = max(res, ans);
    }
    cout << ans << endl;
  }
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define per(i, n) for (int i = (n)-1; i >= 0; i--)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
const int MOD = 1000000007;

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

  vector<ll> a(n + 1, 0), b(m + 1, 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 = -1;

  int jbest = m;

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

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define per(i, n) for (int i = (n)-1; i >= 0; i--)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
const int MOD = 1000000007;

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

  vector<ll> a(n + 1, 0), b(m + 1, 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 = -1;

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

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

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

int main() {
  long long N, M, K;
  cin >> N >> M >> K;
  long long A[N], B[M];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }
  long long a[N + 1], b[M];
  a[0] = 0;
  b[0] = B[0];
  for (int i = 0; i < N; i++) {
    a[i + 1] = a[i] + A[i];
  }
  for (int i = 1; i < M; i++) {
    b[i] = b[i - 1] + B[i];
  }
  int max_book = 0;
  for (int i = 0; i <= N; i++) {
    long long t_book = K - a[i];
    if (t_book < 0)
      continue;
    int up = upper_bound(b, b + M, t_book) - b;
    max_book = max(max_book, i + up);
  }
  cout << max_book << endl;
}

Error: TLE

Fixed submission:

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

int max_book = 0;
int N, M, K;
long long A[200001], B[200001];

int main() {
  cin >> N >> M >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }
  int an = 0;
  int bn = 0;
  int sum_book = 0;
  int t_book = 0;
  // dfs(an, bn, sum_book, t_book);
  stack<int> AN, BN, SUM_BOOK, T_BOOK;
  AN.push(an);
  BN.push(bn);
  SUM_BOOK.push(sum_book);
  T_BOOK.push(t_book);
  map<pair<int, int>, int> mp;
  while (!AN.empty()) {
    int t_book = T_BOOK.top();
    T_BOOK.pop();
    int sum_book = SUM_BOOK.top();
    SUM_BOOK.pop();
    int an = AN.top();
    AN.pop();
    int bn = BN.top();
    BN.pop();
    if (t_book > K)
      continue;
    max_book = max(max_book, sum_book);
    if (an != N) {
      if (mp[make_pair(an + 1, bn)] == 1)
        continue;
      AN.push(an + 1);
      BN.push(bn);
      SUM_BOOK.push(sum_book + 1);
      T_BOOK.push(t_book + A[an]);
      mp[make_pair(an + 1, bn)]++;
    }
    if (bn != M) {
      if (mp[make_pair(an, bn + 1)] == 1)
        continue;
      AN.push(an);
      BN.push(bn + 1);
      SUM_BOOK.push(sum_book + 1);
      T_BOOK.push(t_book + B[bn]);
      mp[make_pair(an, bn + 1)]++;
    }
  }
  cout << max_book << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <cstdint>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

  vector<int64_t> a(N + 1);
  for (int64_t n = 1; n <= N; ++n) {
    cin >> a[n];
    if (n != 0) {
      a[n] += a[n - 1];
    }
  }
  vector<int64_t> b(M);
  for (int64_t m = 0; m < M; ++m) {
    cin >> b[m];
    if (m != 0) {
      b[m] += b[m - 1];
    }
  }
  int64_t idx_b = 0;
  int64_t res = 0;
  for (int64_t idx_a = N; idx_a >= 0; --idx_a) {
    if (a[idx_a] > K) {
      continue;
    }
    int64_t base = a[idx_a];
    int64_t tmp = idx_a;
    for (; idx_b < M; ++idx_b) {
      if (base + b[idx_b] > K) {
        break;
      }
    }
    tmp += idx_b;
    res = max(res, tmp);
  }
  cout << res << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int64_t Solve(const vector<int64_t> &a, const vector<int64_t> b,
              const int64_t limit, size_t idx_a, size_t idx_b, int64_t now_time,
              int64_t now) {
  if (now_time >= limit) {
    return now;
  }
  int64_t read_a = now;
  if (a.size() > idx_a && now_time + a[idx_a] <= limit) {
    read_a = Solve(a, b, limit, idx_a + 1, idx_b, now_time + a[idx_a], now + 1);
  }
  int64_t read_b = now;
  if (b.size() > idx_b && now_time + b[idx_b] <= limit) {
    read_b = Solve(a, b, limit, idx_a, idx_b + 1, now_time + b[idx_b], now + 1);
  }
  return max(read_a, read_b);
}

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

  vector<int64_t> a(N);
  for (int64_t n = 0; n < N; ++n) {
    cin >> a[n];
  }
  vector<int64_t> b(M);
  for (int64_t m = 0; m < M; ++m) {
    cin >> b[m];
  }

  cout << Solve(a, b, K, 0, 0, 0, 0) << endl;

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

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#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 FOR(i, a, b) for (ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i > ll(b); i--)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Umap unordered_map
#define Uset unordered_set

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  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> accum_A(N + 1);
  accum_A.at(0) = 0;
  vector<ll> accum_B(M + 1);
  accum_B.at(0) = 0;
  FOR(i, 1, N + 1) accum_A.at(i) = accum_A.at(i - 1) + A.at(i - 1);
  FOR(i, 1, M + 1) accum_B.at(i) = accum_B.at(i - 1) + B.at(i - 1);

  ll max_sassu = 0;
  ll i_m = M;
  FOR(i_n, 0, N + 1) {
    if (accum_A[i_n] > K) {
      break;
    }

    while (accum_B[i_m] > K - accum_A[i_n])
      i_m -= 1;

    max_sassu = max(i_n + i_m, max_sassu);
  }

  cout << max_sassu << endl;

  return 0;
}

Error: TLE

Fixed submission:

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#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 FOR(i, a, b) for (ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i > ll(b); i--)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Umap unordered_map
#define Uset unordered_set

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  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> accum_A(N + 1);
  accum_A.at(0) = 0;
  vector<ll> accum_B(M + 1);
  accum_B.at(0) = 0;
  FOR(i, 1, N + 1) accum_A.at(i) = accum_A.at(i - 1) + A.at(i - 1);
  FOR(i, 1, M + 1) accum_B.at(i) = accum_B.at(i - 1) + B.at(i - 1);

  ll max_sassu = 0;
  FOR(i_n, 0, N + 1) {
    if (accum_A.at(i_n) > K) {
      break;
    }

    ll i_m = M;
    while (accum_B[i_m] > K - accum_A[i_n])
      i_m -= 1;

    max_sassu = max(i_n + i_m, max_sassu);
  }

  cout << max_sassu << endl;

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

#include <iostream>
using namespace std;
using lld = long long int;

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  lld a[N + 1], b[M + 1];
  a[0] = 0;
  b[0] = 0;
  lld temp = 0;
  for (int i = 1; i < N + 1; i++) {
    lld t = 0;
    cin >> t;
    temp += t;
    a[i] = temp;
  }
  temp = 0;
  for (int i = 1; i < M + 1; i++) {
    lld t = 0;
    cin >> t;
    temp += t;
    b[i] = temp;
  }
  int ans = 0;
  int bestj = M;
  for (int i = 0; i < N + 1; i++) {
    for (int j = bestj; j >= 0; j--) {
      if (a[i] + b[j] <= K) {
        bestj = j;
        if (i + j > ans) {
          ans = i + j;
        }
        break;
      }
    }
  }

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

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

inline long long chmax(long long a, long long b) {
  if (a > b) {
    return a;
  }
  return b;
}

int main() {
  long long N, M, K;
  cin >> N >> M >> K;
  long long a[N], b[M];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> b[i];
  }
  int ans = 0;
  int dp[N + 1][M + 1];
  dp[0][0] = K;
  dp[0][1] = K - b[0];
  dp[1][0] = K - a[0];
  if ((K < a[0]) && (K < b[0])) {
    cout << 0;
    return 0;
  }

  for (int i = 0; i < N + 1; i++) {
    for (int j = 0; j < M + 1; j++) {
      if ((i == 0) && (j == 0)) {
        continue;
      }
      if (j == 0) {
        if (dp[i - 1][j] - a[i - 1] < 0) {
          dp[i][j] = -1;
        } else {
          dp[i][j] = dp[i - 1][j] - a[i - 1];
          ans = chmax(ans, i + j);
        }
      }
      if (i == 0) {
        if (dp[i][j - 1] - b[j - 1] < 0) {
          dp[i][j] = -1;
        } else {
          dp[i][j] = dp[i][j - 1] - b[j - 1];
          ans = chmax(ans, i + j);
        }
      }
      if (dp[i - 1][j] - a[i - 1] >= dp[i][j - 1] - b[j - 1]) {
        if (dp[i - 1][j] - a[i - 1] < 0) {
          dp[i][j] = -1;
        } else {
          dp[i][j] = dp[i - 1][j] - a[i - 1];
          ans = chmax(ans, i + j);
        }
      } else {
        if (dp[i][j - 1] - b[j - 1] < 0) {
          dp[i][j] = -1;
        } else {
          dp[i][j] = dp[i][j - 1] - b[j - 1];
          ans = chmax(ans, i + j);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define ll long long int

using namespace std;

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

  vector<ll> A(n);
  vector<ll> B(m);
  for (auto &a : A)
    cin >> a;
  for (auto &b : B)
    cin >> b;

  ll res = 0;

  ll a = 0;
  ll sum = 0;
  while (sum <= k && a < n) {
    sum += A[a];
    ++a;
  }
  if (sum > k) {
    sum -= A[a - 1];
    --a;
  }
  res = max(res, a);
  // cerr << a << ", 0" << endl;

  ll b = 0;
  while (a >= 0 && b < m) {
    sum += B[b];
    ++b;
    while (sum > k && a >= 0) {
      sum -= A[a - 1];
      --a;
    }
    if (sum <= k) {
      // cerr << a << ", " << b << endl;
      res = max(res, a + b);
    }
  }

  cout << res << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define ll long long int

using namespace std;

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

  vector<ll> A(n);
  vector<ll> B(m);
  for (auto &a : A)
    cin >> a;
  for (auto &b : B)
    cin >> b;

  ll res = 0;
  queue<pair<ll, pair<ll, ll>>> que;
  que.push(make_pair(0, make_pair(0, 0)));

  set<pair<ll, ll>> used;

  while (!que.empty()) {
    auto p = que.front();
    que.pop();
    if (p.second.first < n) {
      if (used.find(make_pair(p.second.first + 1, p.second.second)) ==
          used.end()) {
        ll t = p.first + A[p.second.first];
        if (t <= k) {
          res = max(res, p.second.first + p.second.second + 1);
          que.push(
              make_pair(t, make_pair(p.second.first + 1, p.second.second)));
          used.insert(make_pair(p.second.first + 1, p.second.second));
        }
      }
    }
    if (p.second.second < m) {
      if (used.find(make_pair(p.second.first, p.second.second + 1)) ==
          used.end()) {
        ll t = p.first + B[p.second.second];
        if (t <= k) {
          res = max(res, p.second.first + p.second.second + 1);
          que.push(
              make_pair(t, make_pair(p.second.first, p.second.second + 1)));
          used.insert(make_pair(p.second.first, p.second.second + 1));
        }
      }
    }
  }
  cout << res << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll mod = 1000000007;

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


Error: -6
malloc(): corrupted top size


Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll mod = 1000000007;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1, mod), b(m + 1, mod), A(n + 1), B(m + 1);
  rep(i, n) cin >> a[i];
  rep(j, m) cin >> b[j];
  rep(i, n + 1) A[i + 1] = A[i] + a[i];
  rep(j, m + 1) B[j + 1] = B[j] + b[j];
  ll ans = 0, j = m;
  rep(i, n + 1) {
    if (A[i] > k)
      break;
    while (B[j] > k - A[i]) {
      if (j == 0)
        break;
      j -= 1;
    }
    ans = max(ans, i + j);
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
///****   Hasebul Hassan Chowdhury ***////
#define ms(a, v) memset(a, v, sizeof a)
#define lll long long
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define Read freopen("input.txt", "r", stdin)
#define Write freopen("output.txt", "w", stdout)
#define INF 1e18

vector<lll> Array;
vector<lll> Brray;
void solve() {
  int n, m, k, x;
  lll ans = 0;
  cin >> n >> m >> k;
  Array.push_back(0);
  Brray.push_back(0);
  FOR(i, 1, n) {
    cin >> x;
    Array.push_back(Array[i - 1] + x);
  }
  FOR(j, 1, m) {
    cin >> x;
    Brray.push_back(Brray[j - 1] + x);
  }
  FOR(i, 0, n) {
    lll rem = k - Array[i];
    lll id;
    id = upper_bound(Brray.begin(), Brray.end(), rem) - Brray.begin();
    if (id - 1 >= 0)
      ans = max(ans, (i + (id - 1)));
    // ans=max(ans,(i+(id-1)));
  }
  cout << ans << endl;
}

int main() {
  fast
#ifndef ONLINE_JUDGE
// Read;
// Write;
#endif
  // int t; cin>>t; while(t--) solve();
  solve();
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
///****   Hasebul Hassan Chowdhury ***////
#define ms(a, v) memset(a, v, sizeof a)
#define lll long long
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define Read freopen("input.txt", "r", stdin)
#define Write freopen("output.txt", "w", stdout)
#define INF 1e18

int arr[200005], brr[200005];
int n, m, k;
map<pair<int, int>, int> Map;
// map<pair<int,int>,int>vis;

int DP(int i, int j, lll sum) {
  if (sum > k)
    return -1;
  if (Map[{i, j}] != 0)
    return Map[{i, j}];
  // vis[{i,j}]=1;
  int A = 0, B = 0;
  if (i <= n)
    A = 1 + DP(i + 1, j, sum + arr[i]);
  if (j <= m)
    B = 1 + DP(i, j + 1, sum + brr[j]);
  int E = max(A, B);
  Map[{i, j}] = E;
  return E;
}
void solve() {
  cin >> n >> m >> k;
  FOR(i, 1, n) cin >> arr[i];
  FOR(j, 1, m) cin >> brr[j];
  cout << DP(1, 1, 0) << endl;
}

int main() {
  fast
#ifndef ONLINE_JUDGE
// Read;
// Write;
#endif
  // int t; cin>>t; while(t--) solve();
  solve();
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  ll t, m, n, k;
  t = 1;
  for (int i = 0; i < t; i++) {
    cin >> n >> m >> k;
    ll arr[n], brr[m], prea[n + 1], preb[m + 1];
    prea[0] = preb[0] = 0;
    for (ll j = 0; j < n; j++) {
      cin >> arr[j];
      prea[j + 1] = prea[j] + arr[j];
    }
    for (ll j = 0; j < m; j++) {
      cin >> brr[j];
      preb[j + 1] = preb[j] + brr[j];
    }
    ll maxi = 0;
    for (ll i = 0; i <= n; i++) {
      for (ll j = m; j >= 0; j--) {
        if (prea[i] + preb[j] <= k) {
          maxi = max(maxi, i + j);
          m = j;
          break;
        }
      }
    }
    cout << maxi;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  ll t, m, n, k;
  t = 1;
  for (int i = 0; i < t; i++) {
    cin >> n >> m >> k;
    ll arr[n], brr[n], prea[n + 1], preb[m + 1];
    prea[0] = preb[0] = 0;
    for (ll j = 1; j <= n; j++) {
      cin >> arr[j];
      prea[j] = prea[j - 1] + arr[j];
    }
    for (ll j = 1; j <= m; j++) {
      cin >> brr[j];
      preb[j] = preb[j - 1] + brr[j];
    }
    ll maxi = 0;
    for (ll i = 0; i <= n; i++) {
      for (ll j = m; j >= 0; j--) {
        if (prea[i] + preb[j] <= k) {
          maxi = max(maxi, i + j);
          m = j;
          break;
        }
      }
    }
    cout << maxi;
  }
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  ll n, m;
  ll k;
  vector<ll> a, b;
  cin >> n >> m >> k;
  a.resize(200006);
  b.resize(200006);
  vector<ll> sum_a(200006, 0);
  vector<ll> sum_b(200006, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum_a[i + 1] = sum_a[i] + a[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> b[j];
    sum_b[j + 1] = sum_b[j] + b[j];
  }
  ll ans = 0;
  ll j = m;
  for (ll i = 0; i <= n; i++) {
    if (sum_a[i] > k)
      break;
    ll temp_max = k - sum_a[i];
    while (sum_b[j] > temp_max)
      j--;
    ans = max(ans, i + j);
  }
  cout << ans << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  ll n, m;
  ll k;
  vector<ll> a, b;
  cin >> n >> m >> k;
  a.resize(n);
  b.resize(m);
  vector<ll> sum_a(n + 1, 0);
  vector<ll> sum_b(n + 1, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum_a[i + 1] = sum_a[i] + a[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> b[j];
    sum_b[j + 1] = sum_b[j] + b[j];
  }
  ll ans = 0;
  ll j = m;
  for (ll i = 0; i <= n; i++) {
    if (sum_a[i] > k)
      break;
    ll temp_max = k - sum_a[i];
    while (sum_b[j] > temp_max)
      j--;
    ans = max(ans, i + j);
  }
  cout << ans << "\\n";
  return 0;
}