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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const bool debug = false;
int main() {
  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);
  vector<ll> ta(n + 1), tb(m + 1);
  rep(i, n) { ta.at(i + 1) = ta.at(i) + a.at(i); }
  rep(i, m) { tb.at(i + 1) = tb.at(i) + b.at(i); }
  if (debug) {
    rep(i, n + 1) cout << ta.at(i) << " ";
    cout << endl;
    rep(i, m + 1) cout << tb.at(i) << " ";
    cout << endl;
  }
  int ans = 0;
  rep(i, n + 1) {
    ll lk = k - ta.at(i);
    if (lk < 0)
      continue;
    int l = -1, r = m + 1;
    while (l + 1 < r) {
      int x = (l + r) / 2;
      if (tb.at(x) <= lk)
        l = x;
      else
        r = x;
    }
    if (debug)
      cout << i << " " << l << endl;
    ans = max(ans, i + l);
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  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);
  queue<pair<pair<ll, ll>, ll>> q; // a,b,minute
  q.push({{0, 0}, 0});
  ll ans = 0;
  set<pair<ll, ll>> st;
  while (q.size()) {
    auto x = q.front();
    q.pop();
    if (x.second > k) {
      continue;
    }
    // cout << x.first.first << " " << x.first.second << " " << x.second <<
    // endl;;
    ans = max(ans, x.first.first + x.first.second);
    if (x.first.first < n &&
        st.find({x.first.first + 1, x.first.second}) == st.end()) {
      q.push({{x.first.first + 1, x.first.second},
              x.second + a.at(x.first.first)});
      st.insert({x.first.first + 1, x.first.second});
    }
    if (x.first.second < m &&
        st.find({x.first.first, x.first.second + 1}) == st.end()) {
      q.push({{x.first.first, x.first.second + 1},
              x.second + b.at(x.first.second)});
      st.insert({x.first.first, x.first.second + 1});
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9 + 7
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1), b(m + 1);
  a[n] = 0, b[m] = 0;
  REP(i, n) cin >> a[i];
  REP(i, m) cin >> b[i];
  ll book = 0, time = 0;
  int ai = -1, bi = -1, max;

  while (time + a[ai + 1] <= k && ai + 1 < n) {
    ai++;
    time += a[ai];
    book++;
  }
  while (time + b[bi + 1] <= k && bi + 1 < m) {
    bi++;
    time += b[bi];
    book++;
  }
  max = book;
  while (ai >= 0 && bi + 1 < m) {
    time -= a[ai];
    ai--;
    book--;
    while (time + b[bi + 1] <= k && bi + 1 < m) {
      bi++;
      time += b[bi];
      book++;
    }
    if (max < book)
      max = book;
  }
  cout << max << endl;
  return 0;
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9 + 7
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1), b(m + 1);
  a[n] = 0, b[m] = 0;
  REP(i, n) cin >> a[i];
  REP(i, m) cin >> b[i];
  ll book = 0, time = 0;
  int ai = -1, bi = -1, max;

  while (time + a[ai + 1] <= k && ai + 1 < n) {
    ai++;
    time += a[ai];
    book++;
  }
  while (time + b[bi + 1] <= k && bi + 1 < m) {
    bi++;
    time += b[ai];
    book++;
  }
  max = book;
  while (ai - 1 > 0 && bi + 1 < m) {
    ai--;
    time -= a[ai];
    book--;
    while (time + b[bi + 1] <= k && bi + 1 < m) {
      bi++;
      time += b[ai];
      book++;
    }
    if (max < book)
      max = book;
  }
  cout << max << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using ll = long long;

int n, m;
ll k, tmp;
const ll sz = 2e6 + 10;
ll a[sz], b[sz];
using namespace std;

int main() {
  scanf("%d%d%lld", &n, &m, &k);
  ll prev = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &tmp);
    prev += tmp;
    a[i] = prev;
  }
  prev = 0;
  for (int i = 0; i < m; ++i) {
    scanf("%lld", &tmp);
    prev += tmp;
    b[i] = prev;
  }
  ll mx = 0;
  for (ll i = 0; i < n; i++) {
    if (a[i] > k)
      break;
    ll cnt = 0;
    auto it = lower_bound(b, b + m, k - a[i]) - b;
    if (it == m || b[it] > k - a[i])
      it--;
    cnt += it + 1;
    cnt += (i + 1);
    mx = max(mx, cnt);
  }
  ll mxb = 0;
  for (ll i = 0; i < m; i++) {
    if (b[i] > k)
      break;
    auto it = lower_bound(a, a + n, k - b[i]) - a;
    ll cnt = 0;
    if (it == n || b[it] > k - b[i])
      it--;
    cnt += (i + 1);
    mxb = max(mxb, cnt);
  }

  printf("%d", max(mx, mxb));
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using ll = long long;

int A, B;
ll T, m;
using namespace std;

int bs(vector<ll> v, ll target) {
  int r = v.size() - 1;
  int l = 1;
  int res = 0;

  while (l <= r) {
    int mid = l + (r - l) / 2;
    if (v[mid] <= target) {
      res = max(res, mid);
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  return res;
}

int main() {
  scanf("%d%d%lld", &A, &B, &T);
  vector<ll> a(A + 1), b(B + 1);
  for (int i = 1; i <= A; ++i) {
    scanf("%lld", &m);
    a[i] = m + a[i - 1];
  }
  for (int i = 1; i <= B; ++i) {
    scanf("%lld", &m);
    b[i] = m + b[i - 1];
  }

  int cnt = bs(a, T);
  if (cnt == 0) {
    printf("%d", bs(b, T));
  } else {
    int MAX = cnt;
    for (int i = 1; i <= MAX; ++i) {
      int tmp = bs(b, T - a[i]);
      if (tmp != 0) {
        cnt = max(cnt, tmp + i);
      }
    }
    cnt = max(cnt, bs(b, T));
    printf("%d", cnt);
  }
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n, m, k, ans = 0;
  cin >> n >> m >> k;
  ll a[n + 1] = {0}, b[m + 1] = {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 = 0; i <= n; i++)
    if (k >= a[i])
      ans = max(ans, upper_bound(b + 1, b + 1 + m, k - a[i]) - b - 1 + i);
  cout << ans;
}


Error: TLE

Fixed submission:

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

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> v;
  ll x;
  for (int i = 0; i < n; i++)
    cin >> x, v.push_back(x);
  for (int i = 0; i < m; i++)
    cin >> x, v.push_back(x);
  sort(v.begin(), v.end());
  int cnt = 0;
  while (1) {
    if (v.size() == 0)
      break;
    if (k - v.front() >= 0) {
      k -= v.front();
      v.erase(v.begin());
      cnt++;
    } else
      break;
  }
  cout << cnt;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<long long> a(n + 1), b(m + 1);
  for (int i = 1; i < n + 1; ++i) {
    int x;
    cin >> x;
    a[i] = x + a[i - 1];
  }
  for (int i = 1; i < m + 1; ++i) {
    int x;
    cin >> x;
    b[i] = x + b[i - 1];
  }
  int b_cnt = m;
  int ans = 0;
  for (int i = 0; i < n + 1; ++i) {
    if (k < a[i])
      break;
    while (k < a[i] + b[b_cnt])
      b_cnt--;
    ans = max(ans, i + b_cnt);
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<long long> a(n + 1), b(n + 1);
  for (int i = 1; i < n + 1; ++i) {
    int x;
    cin >> x;
    a[i] = x + a[i - 1];
  }
  for (int i = 1; i < m + 1; ++i) {
    int x;
    cin >> x;
    b[i] = x + b[i - 1];
  }
  int b_cnt = m;
  int ans = 0;
  for (int i = 0; i < n + 1; ++i) {
    if (k < a[i])
      continue;
    while (k < a[i] + b[b_cnt])
      b_cnt--;
    ans = max(ans, i + b_cnt);
  }
  cout << ans << 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;
using ll = long long;
using vi = vector<int>;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
template <typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template <typename T, typename... Args>
void ndarray(vector<T> &vec, int len, Args... args) {
  vec.resize(len);
  for (auto &v : vec)
    ndarray(v, args...);
}

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

  int 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 tot = 0;
  rep(i, m) tot += b[i];

  int j = m;
  int ans = 0;
  rep(i, n + 1) {
    while (j > 0 && tot > k) {
      --j;
      tot -= b[j];
    }
    if (tot > k)
      break;
    ans = max(ans, i + j);
    if (i == n)
      break;
    tot += a[i];
  }
  cout << ans << "\\n";
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
template <typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template <typename T, typename... Args>
void ndarray(vector<T> &vec, int len, Args... args) {
  vec.resize(len);
  for (auto &v : vec)
    ndarray(v, args...);
}

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

  int n, m;
  ll k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  int cnt1 = 0, cnt2 = 0;
  while (1) {
    if ((a[cnt1] < b[cnt2] && cnt1 < n) || (cnt1 < n && cnt2 == m)) {
      k -= a[cnt1];
      if (k < 0)
        break;
      ++cnt1;
    } else if ((a[cnt1] > b[cnt2] && cnt2 < m) || (cnt1 == n && cnt2 < m)) {
      k -= b[cnt2];
      if (k < 0)
        break;
      ++cnt2;
    } else if (a[cnt1] == b[cnt2] && cnt1 < n - 1 && cnt2 < m - 1) {
      int cnt3 = cnt1, cnt4 = cnt2;
      bool ok = true;
      while (1) {
        --cnt3;
        --cnt4;
        if (a[cnt3] < b[cnt4] || cnt4 == m) {
          break;
        } else if (a[cnt3] > b[cnt4] || cnt3 == n) {
          ok = false;
          break;
        }
      }
      if (ok) {
        k -= a[cnt1];
        if (k < 0)
          break;
        ++cnt1;
      } else {
        k -= b[cnt2];
        if (k < 0)
          break;
        ++cnt2;
      }
    } else if (a[cnt1] == b[cnt2] && cnt1 == n - 1 && cnt2 < m - 1) {
      k -= b[cnt2];
      if (k < 0)
        break;
      ++cnt2;
    } else if (a[cnt1] == b[cnt2] && cnt1 < n - 1 && cnt2 == m - 1) {
      k -= a[cnt1];
      if (k < 0)
        break;
      ++cnt1;
    } else if (cnt1 == n && cnt2 == m)
      break;
    if (k <= 0)
      break;
  }
  cout << cnt1 + cnt2 << "\\n";
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int N, M, K;

  cin >> N >> M >> K;
  vector<int> A(N + 1);
  vector<int> B(M + 1);
  vector<int> C(N + 1);
  vector<int> D(M + 1);
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    C[i] = C[i - 1] + A[i];
  }
  for (int i = 1; i <= M; i++) {
    cin >> B[i];
    D[i] = D[i - 1] + B[i];
  }
  vector<int> E(N + 1, 0);
  int count = M;
  for (int i = 0; i <= N; i++) {
    for (int j = count; j >= 0; j--) {
      if (K >= C[i] + D[j]) {
        E[i] = i + j;
        count = j;
        break;
      }
    }
  }
  sort(E.begin(), E.end());
  cout << E[N] << endl;
}


Error: WA

Fixed submission:

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

int main() {

  int n, m, k;
  cin >> n >> m >> k;

  vector<long long> A(n);
  for (long long i = 0; i < (long long)A.size(); i++) {
    cin >> A.at(i);
  }
  vector<long long> B(m);
  for (long long i = 0; i < (long long)B.size(); i++) {
    cin >> B.at(i);
  }
  int cnt = 0;
  int sumtime = 0;
  int u = 0;
  int j = 0;

  while (sumtime < k && u + j != n + m) {
    if (u < n && j < m) {
      if (A.at(u) >= B.at(j)) {
        sumtime += B.at(j);
        j++;
        cnt++;
      }
      if (A.at(u) < B.at(j)) {
        sumtime += A.at(u);
        u++;
        cnt++;
      }
    }
    if (u == n) {
      sumtime += B[j];
      j++;
      cnt++;
    }
    if (j == m) {
      sumtime += A[u];
      u++;
      cnt++;
    }
  }

  if (u + j == m + n) {
    cout << cnt << endl;
  } else {
    cout << cnt - 1 << endl;
  }
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
ll n, m, k, a[200005], b[200005], ans = -1, ma = -1;

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 tim = 0, su = 0, nn = 0, mm = 0;
  for (int i = 0; i < n; i++) {
    if (tim + a[i] <= k)
      tim += a[i], su++, nn++;
    else
      break;
  }
  ans = nn;
  mm = 0;
  ma = 0;
  for (int i = nn - 1; i >= -1; i--) {
    while (b[mm] <= k - tim && mm < m) {
      tim += b[mm], ans++, mm++;
    }
    if (ans > ma)
      ma = ans;
    if (i >= 0)
      tim -= a[i];
    if (i >= 0)
      ans--;
  }
  cout << ma << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
ll n, m, k, a[25], b[25], ans = -1;

void dfs(int sum, int time, int N, int M) {
  if (time + a[N] < k && N < n)
    dfs(sum + 1, time + a[N], N + 1, M);
  if (time + a[M] < k && M < m)
    dfs(sum + 1, time + b[M], N, M + 1);
  if (sum > ans)
    ans = sum;
  return;
}

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];
  dfs(0, 0, 0, 0);
  cout << ans << endl;

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

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

long long N, M, K;
long long A[210000];
long long B[210000];

int main(void) {

  cin >> N >> M >> K;
  for (int i = 1; i <= N; i++)
    cin >> A[i];
  for (int i = 1; i <= M; i++)
    cin >> B[i];

  long long TotalA[N + 1];
  long long TotalB[M + 1];
  int maxA = 0;
  int maxB = 0;

  TotalA[0] = 0;
  TotalB[0] = 0;
  for (int i = 1; i <= N; i++) {
    TotalA[i] = TotalA[i - 1] + A[i];
  }
  for (int i = 1; i <= M; i++) {
    TotalB[i] = TotalB[i - 1] + B[i];
  }

  int limitB = M;
  for (int i = 0; i <= N; i++) {
    for (int j = limitB; j >= 0; j--) {
      if (TotalA[i] + TotalB[j] <= K) {
        limitB = j;
        if (maxA + maxB < i + j) {
          maxA = i;
          maxB = j;
        }
        break;
      }
    }
  }

  cout << maxA + maxB << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

long long N, M, K;
long long A[210000];
long long B[210000];

int main(void) {

  cin >> N >> M >> K;
  for (int i = 1; i <= N; i++)
    cin >> A[i];
  for (int i = 1; i <= M; i++)
    cin >> B[i];

  int book = 0;
  long long time = 0;
  int readA = N;
  int readB = M;
  int TotalA[N + 1];
  int TotalB[M + 1];
  bool exist = false;
  long long maxK = 1000000000;
  int maxN = N;
  int maxM = M;

  TotalA[0] = 0;
  TotalB[0] = 0;
  for (int i = 1; i <= N; i++) {
    if (TotalA[i - 1] + A[i] > maxK) {
      maxN = i - 1;
      break;
    }
    TotalA[i] = TotalA[i - 1] + A[i];
  }
  for (int i = 1; i <= M; i++) {
    if (TotalB[i - 1] + B[i] > maxK) {
      maxM = i - 1;
      break;
    }
    TotalB[i] = TotalB[i - 1] + B[i];
  }

  int T = maxN + maxM;

  for (int i = T; i >= 0; i--) {
    int startA = i - maxM;
    if (startA <= 0)
      startA = 0;
    int limitA = i;
    if (i >= maxM)
      limitA = maxN;
    for (int j = startA; j <= limitA; j++) {
      //            cout << j << "," << i-j << ","<< TotalA[j] + TotalB[i-j] <<
      //            endl;
      if (TotalA[j] + TotalB[i - j] <= K)
        exist = true;
    }
    if (exist) {
      book = i;
      break;
    }
  }

  cout << book << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  vector<ll> A(N), B(M);
  for (ll i = 0; i < N; i++)
    cin >> A.at(i);
  for (ll i = 0; i < M; i++)
    cin >> B.at(i);

  ll ans = 0, i = 0, j = 0, T = K;
  while (true) {
    if (i >= M) {
      i--;
      break;
    }
    if (T - B.at(i) >= 0) {
      T -= B.at(i);
      i++;
      ans++;
    } else {
      i--;
      break;
    }
  }
  ll tmp = ans;
  while (j < N) {
    // cout << tmp << ": i = " << i << ", j = " << j << ", T = " << T << endl;
    if (T - A.at(j) >= 0) {
      T -= A.at(j);
      j++;
      tmp++;
    } else {
      if (i >= 0) {
        T += B.at(i);
        i--;
        tmp--;
      } else
        break;
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  vector<ll> A(N), B(M);
  for (ll i = 0; i < N; i++)
    cin >> A.at(i);
  for (ll i = 0; i < M; i++)
    cin >> B.at(i);

  ll ans = 0, i = 0, j = 0, T = K;
  while (i < M) {
    if (T - B.at(i) >= 0) {
      T -= B.at(i);
      i++;
      ans++;
    } else {
      i--;
      break;
    }
  }
  ll tmp = ans;
  while (j < N) {
    // cout << tmp << ": i = " << i << ", j = " << j << ", T = " << T << endl;
    if (T - A.at(j) >= 0) {
      T -= A.at(j);
      j++;
      tmp++;
    } else {
      if (i >= 0) {
        T += B.at(i);
        i--;
        tmp--;
      } else
        break;
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define all(x) x.begin(), x.end()
ll power(ll a, ll b) {
  ll res = 1;
  a = a % mod;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return res;
}
ll invmod(ll a) { return power(a, mod - 2); }
int main(void) {
  FIO int t = 1;
  // cin >> t;
  while (t--) {
    ll n, m, k;
    cin >> n >> m >> k;
    ll a[n + 1], b[m + 1];
    a[0] = b[0] = 0;
    for (int i = 1; i <= n; i++)
      cin >> a[i];
    for (int i = 1; i <= m; i++)
      cin >> b[i];
    for (int i = 0; i < n; i++)
      a[i + 1] += a[i];
    for (int i = 0; i < m; i++)
      b[i + 1] += b[i];
    int ans = 0, j = m;
    for (int i = 0; i <= n; i++) {
      if (a[i] > k)
        break;
      while (j >= 0 && b[j] > k - a[i])
        j--;
      ans = max(ans, i + j);
    }
    cout << ans << "\\n";
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define all(x) x.begin(), x.end()
ll power(ll a, ll b) {
  ll res = 1;
  a = a % mod;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return res;
}
ll invmod(ll a) { return power(a, mod - 2); }
int main(void) {
  FIO int t = 1;
  // cin >> t;
  while (t--) {
    ll n, m, k;
    cin >> n >> m >> k;
    ll a[n + 1], b[n + 1];
    a[0] = b[0] = 0;
    for (int i = 1; i <= n; i++)
      cin >> a[i];
    for (int i = 1; i <= m; i++)
      cin >> b[i];
    for (int i = 0; i < n; i++)
      a[i + 1] += a[i];
    for (int i = 0; i < m; i++)
      b[i + 1] += b[i];
    int ans = 0, j = m;
    for (int i = 0; i <= n; i++) {
      if (a[i] > k)
        break;
      while (j >= 0 && b[j] > k - a[i])
        j--;
      ans = max(ans, i + j);
    }
    cout << ans << "\\n";
  }
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  ll a[n + 1], b[m + 1];
  a[0] = 0;
  b[0] = 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];
  }

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

  cout << ans << endl;

  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int n, m;
  int k;
  cin >> n >> m >> k;
  ll a[n + 1], b[m + 1];
  a[0] = 0;
  b[0] = 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];
  }

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

  cout << ans << endl;

  return 0;
}