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

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N, M, K;
  vector<long> A = {0};
  vector<long> B = {0};
  cin >> N >> M >> K;
  for (int i = 0; i < N; i++) {
    long a;
    cin >> a;
    a += A.at(i);
    A.push_back(a);
  }
  for (int i = 0; i < M; i++) {
    long b;
    cin >> b;
    b += B.at(i);
    B.push_back(b);
  }

  int maxij = 0;
  int oldj = 0;
  for (int i = 0; i <= N; i++) {
    for (int j = oldj; j <= M; j++) {
      if (B.at(M - j) <= K - A.at(i)) {
        maxij = max(maxij, i + M - j);
        oldj = j;
        break;
      }
    }
  }
  cout << maxij << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N, M, K;
  vector<long> A = {0};
  vector<long> B = {0};
  cin >> N >> M >> K;
  for (int i = 0; i < N; i++) {
    long a;
    cin >> a;
    a += A.at(i);
    A.push_back(a);
  }
  for (int i = 0; i < M; i++) {
    long b;
    cin >> b;
    b += B.at(i);
    B.push_back(b);
  }

  int maxij = 0;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      if (B.at(M - j) <= K - A.at(i)) {
        maxij = max(maxij, i + M - j);
        break;
      }
    }
  }
  cout << maxij << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli, lli> pii;
#define rep(i, n) for (lli i = 0; i < (lli)(n); i++)
#define YN(x) cout << (bool x ? "Yes" : "No") << endl;
#define out(s) cout << s << endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(), s.end()
void vout(vi v) {
  for (lli i = 0; i < v.size(); i++)
    cout << v.at(i) << endl;
}
int main() {
  lli n, m, k, ans = 0;
  cin >> n >> m >> k;
  vi a(n + 1), b(m + 1);
  a[0] = 0;
  b[0] = 0;
  rep(i, n) {
    lli an;
    cin >> an;
    a[i + 1] = a[i] + an;
  }
  rep(i, m) {
    lli bn;
    cin >> bn;
    b[i + 1] = b[i] + bn;
  }
  lli prev = m;
  rep(i, n + 1) {
    lli tmp = k - a[i];
    if (tmp < 0) {
      break;
    }
    for (lli j = prev; j >= 0; j--) {
      if (b[j] <= tmp) {
        prev = j;
        ans = max(ans, i + j);
        break;
      } else
        continue;
    }
  }
  out(ans);
}

Error: TLE

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli, lli> pii;
#define rep(i, n) for (lli i = 0; i < (lli)(n); i++)
#define YN(x) cout << (bool x ? "Yes" : "No") << endl;
#define out(s) cout << s << endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(), s.end()
void vout(vi v) {
  for (lli i = 0; i < v.size(); i++)
    cout << v.at(i) << endl;
}
int main() {
  lli n, m, k, ans = 0;
  cin >> n >> m >> k;
  vi a(n + 1), b(m + 1);
  a[0] = 0;
  b[0] = 0;
  rep(i, n) {
    lli an;
    cin >> an;
    a[i + 1] = a[i] + an;
  }
  rep(i, m) {
    lli bn;
    cin >> bn;
    b[i + 1] = b[i] + bn;
  }
  rep(i, n + 1) {
    lli tmp = k - a[i];
    if (tmp < 0) {
      break;
    }
    auto itr = upper_bound(all(b), tmp);
    ans = max(ans, (lli)(distance(b.begin(), itr) + i - 1));
  }
  out(ans);
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

ll a[200005], b[200005];
void solve() {
  ll n, m, t, cnt = 0;
  cin >> n >> m >> t;
  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];
  ll j = m;
  for (ll i = 0; i <= n; i++) {
    ll f = 0;
    while (b[j] + a[i] > t) {
      --j;
      if (j < 0) {
        f = 10;
        break;
      }
    }
    if (f)
      break;
    cnt = max(cnt, i + j);
  }
  cout << cnt << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  // int t;cin>>t;while(t--)
  solve();
  return 0;
}


Error: 0

Fixed submission:

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

ll a[200005], b[200005];
void solve() {
  ll n, m, t, cnt = 0;
  cin >> n >> m >> t;
  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];
  ll j = m;
  for (ll i = 0; i <= n; i++) {
    while (b[j] + a[i] > t)
      --j;
    cnt = max(cnt, i + j);
  }
  cout << cnt << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  // int t;cin>>t;while(t--)
  solve();
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;

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

  // 読書時間の合計時間表
  int A[200050], B[200050];
  // 読まないときは0
  A[0] = 0;
  B[0] = 0;
  // 考慮する意味のある範囲
  int A_max = N;
  bool A_check = false;
  int B_max = M;
  bool B_check = false;
  for (int i = 1; i <= N; i++) {
    int Ai;
    cin >> Ai;
    A[i] = Ai + A[i - 1];
    if (A[i] > K && (!A_check)) {
      // i冊目を考える必要は皆無
      A_max = i - 1;
      A_check = true;
    }
  }
  for (int i = 1; i <= M; i++) {
    int Bi;
    cin >> Bi;
    B[i] = Bi + B[i - 1];
    if (B[i] > K && (!B_check)) {
      // i冊目を考える必要は皆無
      B_max = i - 1;
      B_check = true;
    }
  }

  // Aの読む本数を増やして走査
  int ans = 0;
  int Screen_Index[200050]; // Bの操作位置に関する関する情報
  Screen_Index[0] = B_max; // A=0のとき、Bは一番大きいところから走査する。
  for (int i = 0; i <= A_max; i++) {
    for (int j = Screen_Index[i]; j >= 0; j--) {
      // オーバーしなくなったら抜け出す
      if (A[i] <= K - B[j]) {
        if (i + 1 <= N)
          Screen_Index[i + 1] = j;
        ans = max(ans, i + j);
        break;
      }
    }
  }

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

Error: 0

Fixed submission:

#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;
int main(void) {
  int N, M;
  int K;
  cin >> N >> M >> K;

  // 読書時間の合計時間表
  long long A[200050], B[200050];
  // 読まないときは0
  A[0] = 0;
  B[0] = 0;
  for (int i = 1; i <= N; i++) {
    int Ai;
    cin >> Ai;
    A[i] = Ai + A[i - 1];
  }
  for (int i = 1; i <= M; i++) {
    int Bi;
    cin >> Bi;
    B[i] = Bi + B[i - 1];
  }

  // Aの読む本数を増やして走査
  int ans = 0;
  int Screen_Index[200050]; // Bの操作位置に関する関する情報
  Screen_Index[0] = M; // A=0のとき、Bは一番大きいところから走査する。
  for (int i = 0; i <= N; i++) {
    // Bの走査開始位置を受け取る
    int Bj_max = Screen_Index[i];
    for (int j = Bj_max; A[i] > K - B[j]; j--) {
      // はじめはオーバーするはず
      Screen_Index[i]--;
    }
    // 条件達成
    // 次の操作位置を更新
    Screen_Index[i + 1] = Screen_Index[i];
    ans = max(ans, i + Screen_Index[i]);
  }

  cout << ans << endl;

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

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

int N, M;
ll K;
vector<int> A, B;
int ans = 0;
ll now = 0;

void newbfs(int ai, int bi, ll now) {
  while (bi < M) {
    if (now + B.at(bi) > K)
      break;
    now += B.at(bi);
    bi++;
  }
  ans = max(ans, ai + bi);

  if (ai == 0)
    return;
  ai--;
  now -= A.at(ai);
  newbfs(ai, bi, now);
}

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

  int ai = 0;
  ll now = 0;
  while (ai < N) {
    if (now + A.at(ai) > K)
      break;
    now += A.at(ai);
    ai++;
  }
  ans = ai;

  newbfs(ai, 0, now);
  cout << ans << endl;
}


Error: TLE

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 P = pair<int, int>;

int N, M;
ll K;
vector<int> A, B;
int ans = 0;
ll now = 0;

void bfs(int ai, int bi, ll now, bool flag) {
  if (now > K) {
    ans = max(ans, ai + bi - 1);
    return;
  }

  if (ai == N && bi == M) {
    ans = max(ans, ai + bi);
    return;
  }

  if (ai < N && !flag) {
    bfs(ai + 1, bi, now + A.at(ai), false);
  }
  if (bi < M) {
    bfs(ai, bi + 1, now + B.at(bi), true);
  }
}

int main() {
  cin >> N >> M >> K;
  A = vector<int>(N);
  B = vector<int>(M);
  rep(i, N) cin >> A.at(i);
  rep(i, M) cin >> B.at(i);
  bfs(0, 0, 0, false);
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

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

  int64_t time = 0;

  cin >> N >> M >> K;

  int max_ij = 0;
  int max_j = M;

  vector<int> A(N, 0);
  vector<int> B(M, 0);

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

  int i, j;

  for (i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  for (i = 0; i < M; i++) {
    cin >> B.at(i);
  }

  for (i = 0; i <= N; i++) {
    if (i == 0) {
      A_sum[i] = 0;
    } else {
      A_sum[i] += A_sum[i - 1] + A.at(i - 1);
    }
  }

  for (i = 0; i <= M; i++) {
    if (i == 0) {
      B_sum[i] = 0;
    } else {
      B_sum[i] += B_sum[i - 1] + B.at(i - 1);
    }
  }

  for (i = 0; i <= N; i++) {
    if (A_sum[i] > K) {
      break;
    }

    for (j = max_j; j >= 0; j--) {
      if (B_sum[j] <= K - A_sum[i]) {
        max_j = j;
        break;
      }
    }

    max_ij = max(i + j, max_ij);
  }

  cout << max_ij << endl;

  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  int64_t time = 0;

  int max_ij = 0;
  int max_j = M;

  cin >> N >> M >> K;

  vector<int> A(N, 0);
  vector<int> B(M, 0);

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

  int i, j;

  for (i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  for (i = 0; i < M; i++) {
    cin >> B.at(i);
  }

  for (i = 0; i <= N; i++) {
    if (i == 0) {
      A_sum[i] = 0;
    } else {
      A_sum[i] += A_sum[i - 1] + A.at(i - 1);
    }
  }

  for (i = 0; i <= M; i++) {
    if (i == 0) {
      B_sum[i] = 0;
    } else {
      B_sum[i] += B_sum[i - 1] + B.at(i - 1);
    }
  }

  for (i = 0; i <= N; i++) {
    if (A_sum[i] > K) {
      break;
    }

    for (j = max_j; j >= 0; j--) {
      if (B_sum[j] <= K - A_sum[i]) {
        max_j = j;
        break;
      }
    }

    max_ij = max(i + j, max_ij);
  }

  cout << max_ij << 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 < n; i++)
typedef long long ll;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> A(n + 1);
  vector<ll> B(m);
  A[0] = 0;
  rep(i, n) cin >> A.at(i + 1);
  rep(i, m) cin >> B.at(i);
  rep(i, n) A[i + 1] = A[i + 1] + A[i];
  rep(i, m - 1) B[i + 1] = B[i + 1] + B[i];
  ll ans = 0;
  for (ll i = 0; i < n + 1; i++) {
    if (k - A[i] < 0)
      continue;
    auto Iter1 = upper_bound(B.begin(), B.end(), k - A[i]);
    ll j = Iter1 - B.begin();
    // cout << i + 1 << ' ' <<  j << endl ;
    ans = max(i + j, ans);
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> A(n);
  vector<ll> B(m);
  rep(i, n) cin >> A.at(i);
  rep(i, m) cin >> B.at(i);
  vector<ll> Ans(400005);
  Ans[0] = 0;
  ll j = 0, l = 0;
  ll ans = 0;
  for (ll i = 0; Ans.at(i) <= k; i++) {
    if (A[j] <= B[l]) {
      Ans[i + 1] = Ans[i] + A[j];
      j++;
    } else {
      Ans[i + 1] = Ans[i] + B[l];
      l++;
    }
    ans = i;
    // cout << i << ' ' << j << ' '<< l << endl ;
    // cout << Ans[i+1] <<endl;
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
  ll n, m, a, b, ans = 0, k;
  cin >> n >> m >> k;
  vector<ll> suma(n + 10), sumb(m + 10);
  for (int i = 0; i < n; i++) {
    cin >> a;
    suma[i + 1] = suma[i] + a;
  }
  for (int i = 0; i < m; i++) {
    cin >> b;
    sumb[i + 1] = sumb[i] + b;
  }
  for (int i = 0; i <= n; i++) {
    while (m >= 0 && suma[i] + sumb[m] > k) {
      m--;
    }
    if (m >= 0) {
      ans = max(ans, i + m);
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
  ll n, m, a, b, ans = 0, k;
  cin >> n >> m >> k;
  vector<ll> suma(n + 10), sumb(n + 10);
  for (int i = 0; i < n; i++) {
    cin >> a;
    suma[i + 1] = suma[i] + a;
  }
  for (int i = 0; i < m; i++) {
    cin >> b;
    sumb[i + 1] = sumb[i] + b;
  }
  for (int i = 0; i <= n; i++) {
    while (m >= 0 && suma[i] + sumb[m] > k) {
      m--;
    }
    if (m >= 0) {
      ans = max(ans, i + m);
    }
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, m, k, temp;
  cin >> n >> m >> k;
  vector<long> a(n + 1, 0), b(m + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> temp;
    a.at(i) = a.at(i - 1) + temp;
  }
  for (int i = 1; i <= m; i++) {
    cin >> temp;
    b.at(i) = b.at(i - 1) + temp;
  }
  int b_idx = m, ans = 0;
  for (int i = 0; i <= n; i++) {
    if (a.at(i) > k)
      break;
    while (a.at(i) + b.at(b_idx) > k)
      b_idx--;
    ans = max(ans, i + b_idx);
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, k;
  cin >> n >> m >> k;
  vector<long long int> a(200000);
  vector<long long int> b(200000);
  for (long long int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (long long int i = 0; i < m; i++) {
    cin >> b.at(i);
  }
  long long int time = 0, count = 0, ans = 0, layer = 1;

  for (long long int i = 0; i < (n + m); i++) {
    long long int num = i;
    if (a.at(i) == -1 || b.at(i) == -1) {
      for (long long int j = 0; j < (n + m); j++) {
        if (a.at(i + layer) == -1 || b.at(i + layer) == -1) {

        } else {
          goto A;
        }
        layer++;
      }
    }
  A:
    if (a.at(i) == -1) {
      time = min(a.at(i + layer), b.at(i));
      if (time <= k)
        count++;
    } else {
      time = min(a.at(i), b.at(i + layer));
      if (time <= k)
        count++;
    }
    ans += time;
    if (a.at(i) == time)
      a.at(i) = -1;
    else
      b.at(i) = -1;
    if (ans >= k)
      break;
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[200000], b[200000];
ll sumA[200010] = {0}, sumB[200010] = {0};

ll mx(ll x, ll y) {
  if (x > y)
    return x;
  else
    return y;
}
int main() {
  int n, m;
  ll k, ans;
  cin >> n >> m >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sumA[i + 1] = sumA[i] + (ll)a[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
    sumB[i + 1] = sumB[i] + (ll)b[i];
  }
  ans = 0;
  int j = m;
  for (int i = 0; i <= n; ++i) {
    if (sumA[i] > k)
      break;
    while (sumA[i] + sumB[j] > k)
      --j;
    ans = mx(i + j, ans);
  }
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[100000], b[100000];

ll mx(ll x, ll y) {
  if (x >= y)
    return x;
  else
    return y;
}
int main() {
  ll n, m, k, x, c, sum, ans;
  cin >> n >> m >> k;
  c = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i + 1] += a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    b[i + 1] += b[i];
  }
  ans = 0;
  for (int i = 0, j = m; i <= n; i++) {
    if (a[i] > k)
      break;
    while (a[i] + b[j] > k)
      --j;
    ans = mx(i + j, 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 < (n); i++)
#define rep2(i, n) for (int i = 1; i <= (n); i++)
typedef long long ll;

ll a[200001];
ll b[200001];
int main() {
  int N, M, K;
  cin >> N >> M >> K;
  a[0] = 0;
  b[0] = 0;
  rep2(i, N) {
    int x;
    cin >> x;
    a[i] = i == 1 ? x : x + a[i - 1];
  }
  rep2(i, M) {
    int x;
    cin >> x;
    b[i] = i == 1 ? x : x + b[i - 1];
  }
  int j = M, ans = 0;
  for (int i = 0; i <= N; i++) {
    if (a[i] > K)
      break;
    while (a[i] + b[j] > K)
      j--;
    ans = max(ans, i + j);
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

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

// int a[200001];
// int b[200001];
ll a[10];
ll b[10];
int main() {
  int N, M, K;
  cin >> N >> M >> K;
  a[0] = 0;
  b[0] = 0;
  rep2(i, N) {
    int x;
    cin >> x;
    a[i] = i == 1 ? x : x + a[i - 1];
  }
  rep2(i, M) {
    int x;
    cin >> x;
    b[i] = i == 1 ? x : x + b[i - 1];
  }
  int j = M, ans = 0;
  for (int i = 0; i <= N; i++) {
    if (a[i] > K)
      break;
    while (a[i] + b[j] > K)
      j--;
    ans = max(ans, i + j);
  }

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

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set                                                            \\
  tree<pairs, null_type, greater<pairs>, rb_tree_tag,                          \\
       tree_order_statistics_node_update>
#define ll long long
#define lld long double
#define vc vector<ll>
#define MOD (ll)(1e9 + 7)
typedef pair<ll, ll> pairs;
ll power(ll a, ll b) {
  ll res = 1;
  a = a % MOD;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % MOD;
      b--;
    }
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}

int main() {
  // your code goes here
  std::ios::sync_with_stdio(false);
  ll t, n, i, j, k, l, c, f, m;
  cin >> n >> m >> k;
  vc a(n + 1), b(m + 1);
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  for (i = 1; i <= m; i++) {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  j = 0;
  ll ans = 0;
  for (i = n; i >= 0; i--) {
    for (; j <= m; j++) {
      if (a[i] + b[j] > k)
        break;
      else
        ans = max(ans, i + j);
    }
  }
  cout << ans << "\\n";
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set                                                            \\
  tree<pairs, null_type, greater<pairs>, rb_tree_tag,                          \\
       tree_order_statistics_node_update>
#define ll long long
#define lld long double
#define vc vector<ll>
#define MOD (ll)(1e9 + 7)
typedef pair<ll, ll> pairs;
ll power(ll a, ll b) {
  ll res = 1;
  a = a % MOD;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % MOD;
      b--;
    }
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}

int main() {
  // your code goes here
  std::ios::sync_with_stdio(false);
  ll t, n, i, j, k, l, c, f, m;
  cin >> n >> m >> k;
  queue<ll> a, b;
  i = 1;
  while (i <= n) {
    cin >> c;
    a.push(c);
    i++;
  }
  i = 1;
  while (i <= m) {
    cin >> c;
    b.push(c);
    i++;
  }
  f = max(n, m);
  c = 0;
  ll mn;
  f = 0;
  for (i = 1; i <= n + m; i++) {
    if (b.empty() || a.front() < b.front()) {
      if (c + a.front() <= k) {
        c += a.front();
        // cout<<c<<"\\n";
        a.pop();
        f++;
      } else
        break;
    } else if (a.empty() || b.front() <= a.front()) {
      if (c + b.front() <= k) {
        c += b.front();
        // cout<<c<<"\\n";
        b.pop();
        f++;

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

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define SZ(c) int(c.size())
#define pb push_back
#define loop(i, start, n) for (int i = start; i < n; i++)
#define rloop(i, start, n) for (int i = start; i > n; i--)

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
const ll inf = 2e9 + 3;

void solve() {
  int tc = 1;
  // cin >> tc;
  while (tc--) {
    ll n, m, k, res = 0;
    cin >> n >> m >> k;
    vll va(n + 1), vb(m + 1);
    ll A = 0, B = 0;
    loop(i, 1, n + 1) {
      cin >> va[i];
      va[i] = va[i] + va[i - 1];
    }
    loop(i, 1, m + 1) {
      cin >> vb[i];
      vb[i] = vb[i] + vb[i - 1];
    }
    ll b = m, a = n;
    loop(i, 1, n + 1) if (va[i] <= k) a = i;
    loop(i, 1, m + 1) if (vb[i] <= k) b = i;
    loop(i, 0, a + 1) {
      if (vb[b] + va[i] <= k)
        res = max(res, i + b);
      else
        b--;
      /*loop(j,0,b+1) {
          if (va[i] + vb[j] <= k) res = max(res,(ll)(i+j));
      }*/
    }
    cout << res;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, m, k, a;
  vector<int> nbooks, mbooks;
  cin >> n >> m >> k;
  if (1 > n || n > 200000 || 1 > m || m > 200000 || 1 > k || k > 1000000000)
    return 0;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (1 > a || a > 1000000000)
      return 0;
    nbooks.push_back(a);
  }
  for (int i = 0; i < m; i++) {
    cin >> a;
    if (1 > a || a > 1000000000)
      return 0;
    mbooks.push_back(a);
  }
  int smallest = 0, total = 0;
  int nindex = 0, mindex = 0;
  int counter = 0;
  while (true) {
    if (counter == n + m) {
      cout << counter;
      return 0;
    }
    if (nbooks[nindex] < mbooks[mindex]) {
      smallest = nbooks[nindex];
      nindex++;
      if (smallest + total <= k)
        total = total + smallest;
      else
        break;
    } else {
      smallest = mbooks[mindex];
      mindex++;
      if (smallest + total <= k)
        total = total + smallest;
      else
        break;
    }
    counter++;
  }
  cout << counter;
  return 0;
}