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

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v)                                                              \\
  v.erase(unique(v.begin(), v.end()), v.end()) // sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

signed main() {
  cin >> N >> M >> K;
  vector<ll> a(N), b(M);
  cin >> a;
  cin >> b;
  vector<ll> sb(M);
  sb[0] = b[0];
  REPS(i, M - 1) { sb[i] = sb[i - 1] + b[i]; }
  auto itr = upper_bound(ALL(sb), K);
  ans = itr - sb.begin();
  dump(sb);
  dump(ans);
  REP(i, N) {
    K -= a[i];
    if (K < 0) {
      break;
    }
    auto itr = upper_bound(ALL(sb), K);
    ans = max(ans, (ll)(itr - sb.begin() + i + 1));
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v)                                                              \\
  v.erase(unique(v.begin(), v.end()), v.end()) // sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

signed main() {
  cin >> N >> M >> K;
  vector<ll> a(N), b(M);
  cin >> a;
  cin >> b;
  vector<ll> sb(M);
  sb[0] = b[0];
  REPS(i, N - 1) { sb[i] = sb[i - 1] + b[i]; }
  auto itr = upper_bound(ALL(sb), K);
  ans = itr - sb.begin();
  dump(sb);
  dump(ans);
  REP(i, N) {
    K -= a[i];
    if (K < 0) {
      break;
    }
    auto itr = upper_bound(ALL(sb), K);
    ans = max(ans, (ll)(itr - sb.begin() + i + 1));
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
const ll INF = 1e18 + 1;

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

  ll n, m, k;
  cin >> n >> m >> k;

  vector<ll> a(n), b(m);

  ll ai = -1, bi = -1;

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

    if (a[i] <= k) {
      ai = i;
    }
  }

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

    if (b[i] <= k) {
      bi = i;
    }
  }
  ll ans = max(ai + 1, bi + 1);

  ll idx = 0, tai = ai;

  for (ll i = tai; i >= 0; i--) {
    while (idx < m && b[idx] + a[i] <= k) {
      idx++;
    }
    ans = max(ans, i + 1 + idx);
  }

  idx = 0;
  ll tbi = bi;

  for (ll i = tbi; i >= 0; i--) {
    while (idx < n && a[idx] + b[i] <= k) {
      idx++;
    }
    ans = max(ans, i + 1 + idx);
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
const ll INF = 1e18 + 1;

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

  ll n, m, k;
  cin >> n >> m >> k;

  vector<ll> a(n), b(m);

  ll ai = -1, bi = -1;

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

    if (a[i] <= k) {
      ai = i;
    }
  }

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

    if (b[i] <= k) {
      bi = i;
    }
  }
  ll ans = max(ai + 1, bi + 1);

  ll idx = 0, tai = ai;

  for (ll i = tai; i >= 0; i--) {
    while (idx < m && b[idx] + a[tai] <= k) {
      idx++;
    }
    ans = max(ans, tai + 1 + idx);
  }

  idx = 0;
  ll tbi = bi;

  for (ll i = tbi; i >= 0; i--) {
    while (idx < n && a[idx] + b[tai] <= k) {
      idx++;
    }
    ans = max(ans, tbi + 1 + idx);
  }

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

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

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  vector<ll> s(n + 1), t(m + 1);
  s[0] = 0;
  rep(i, n) { s[i + 1] = s[i] + a[i]; }
  t[0] = 0;
  rep(i, m) { t[i + 1] = t[i] + b[i]; }
  int ans = 0;
  rep(i, n + 1) {
    ll res = k - s[i];
    if (res < 0)
      continue;
    int now = i;
    auto itr = upper_bound(t.begin(), t.end(), res);
    now += distance(t.begin(), itr) - 1;
    ans = max(ans, now);
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

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() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  vector<ll> s(n + 1);
  s[0] = 0;
  rep(i, n) { s[i + 1] = s[i] + a[i]; }
  int ans = 0;
  rep(i, n + 1) {
    if (s[i] > k)
      continue;
    else {
      int res = k - s[i];
      int now = 0;
      rep(j, m) {
        if (res - b[j] < 0) {
          break;
        } else {
          res -= b[j];
          now++;
        }
      }
      ans = max(ans, now + i);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll n, m, k, aa, bb, ans, f_ans, jj;
  cin >> n >> m >> k;
  vector<ll> a(n + 1);
  vector<ll> b(m + 1);
  f_ans = 0;
  bool answer = false;
  rep(i, n + 1) {

    if (i == 0)
      a[i] = 0;
    else {
      cin >> aa;
      a[i] = a[i - 1] + aa;
    }
  }
  rep(i, m + 1) {
    if (i == 0)
      b[i] = 0;
    else {
      cin >> bb;
      b[i] = b[i - 1] + bb;
    }
  }
  ll j = m;
  rep(i, n + 1) {
    if (k < a[i])
      break;
    while (b[j] > k - a[i])
      j--;
    f_ans = max(f_ans, i + j);
  }
  cout << f_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>;
const int MX = 1000005;

int main() {
  int n, m, k, aa, bb, ans, f_ans;
  cin >> n >> m >> k;
  vector<int> a(n + 1);
  vector<int> b(m + 1);
  f_ans = 0;
  rep(i, n + 1) {

    if (i == 0)
      a[i] = 0;
    else {
      cin >> aa;
      a[i] = a[i - 1] + aa;
    }
  }
  rep(i, m + 1) {
    if (i == 0)
      b[i] = 0;
    else {
      cin >> bb;
      b[i] = b[i - 1] + bb;
    }
  }
  rep(i, n + 1) {
    if (k < a[i])
      break;
    rep(j, m + 1) {
      if (k < a[i] + b[j]) {
        break;
      } else if (k >= a[i] + b[j]) {
        ans = i + j;
        f_ans = max(ans, f_ans);
      }
    }
  }
  cout << f_ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define fl(i, n) for (i = 0; i < n; i++)
#define fld(i, a, b) for (i = a; i > b; i--)
#define fli(i, a, n) for (i = a; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 998244353
#define all(x) x.begin(), x.end()
#define speedup ios_base::sync_with_stdio(false), cin.tie(0)
using namespace std;
ll power(ll x, ll y) {
  ll out = 1;
  while (y > 0) {
    if (y & 1)
      out = (out * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return out % mod;
}
ll inverse(ll a) { return power(a, mod - 2) % mod; }
ll pref_v1[200001];
ll pref_v2[200001];
bool check(ll mid, ll k, ll m, ll n) {
  ll i = 0, j;
  while (i <= mid && i <= n) {
    if (mid - i <= m) {
      j = mid - i;
      if (pref_v1[i] + pref_v2[j] <= k)
        return true;
    }
    i++;
  }
  return false;
}
void comp() {
  ll i, j, k, n, m;
  cin >> n >> m >> k;
  vector<ll> v1(n + 1), v2(m + 1);
  fl(i, n) { cin >> v1[i + 1]; }
  fl(i, m) { cin >> v2[i + 1]; }
  pref_v2[1] = v2[1];
  pref_v1[1] = v1[1];
  fli(i, 2, n + 1) pref_v1[i] = pref_v1[i - 1] + v1[i];
  fli(i, 2, m + 1) pref_v2[i] = pref_v2[i - 1] + v2[i];
  ll low = 0, high = (n + m), mid;
  ll ans = 0;
  while (low <= high) {
    mid = (low + high) / 2;
    if (check(mid, k, m, n)) {
      low = mid + 1;
      ans = mid;
    } else {
      high = mid - 1;
    }
  }
  cout << ans << "\\n";
}
int main() {
  speedup;
  ll i = 0, t;
  t = 1;
  // cin>>t;
  while (t--) {
    comp();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define fl(i, n) for (i = 0; i < n; i++)
#define fld(i, a, b) for (i = a; i > b; i--)
#define fli(i, a, n) for (i = a; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 998244353
#define all(x) x.begin(), x.end()
#define speedup ios_base::sync_with_stdio(false), cin.tie(0)
using namespace std;
ll power(ll x, ll y) {
  ll out = 1;
  while (y > 0) {
    if (y & 1)
      out = (out * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return out % mod;
}
ll inverse(ll a) { return power(a, mod - 2) % mod; }
ll pref_v1[2001];
ll pref_v2[2001];
bool check(ll mid, ll k, ll m, ll n) {
  ll i = 0, j;
  while (i <= mid && i <= n) {
    if (mid - i <= m) {
      j = mid - i;
      if (pref_v1[i] + pref_v2[j] <= k)
        return true;
    }
    i++;
  }
  return false;
}
void comp() {
  ll i, j, k, n, m;
  cin >> n >> m >> k;
  vector<ll> v1(n + 1), v2(m + 1);
  fl(i, n) { cin >> v1[i + 1]; }
  fl(i, m) { cin >> v2[i + 1]; }
  pref_v2[1] = v2[1];
  pref_v1[1] = v1[1];
  fli(i, 2, n + 1) pref_v1[i] = pref_v1[i - 1] + v1[i];
  fli(i, 2, m + 1) pref_v2[i] = pref_v2[i - 1] + v2[i];
  ll low = 0, high = (n + m), mid;
  ll ans = 0;
  while (low <= high) {
    mid = (low + high) / 2;
    if (check(mid, k, m, n)) {
      low = mid + 1;
      ans = mid;
    } else {
      high = mid - 1;
    }
  }
  cout << ans << "\\n";
}
int main() {
  speedup;
  ll i = 0, t;
  t = 1;
  // cin>>t;
  while (t--) {
    comp();
  }
  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;

int main() {
  int n, m, k, ans = 0;
  vector<long long int> a(200010, 0), b(200010, 0);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    int ai;
    cin >> ai;
    a[i] = a[i - 1] + ai;
  }
  for (int i = 1; i <= m; i++) {
    int bi;
    cin >> bi;
    b[i] = b[i - 1] + bi;
  }
  int memo = m;
  for (int i = 0; i <= n; i++) {
    if (a[i] > k)
      goto end_loop;
    for (int j = memo; j >= 0; j--) {
      if (b[j] <= k - a[i]) {
        ans = max(ans, i + j);
        memo = j;
        break;
      }
    }
  }
end_loop:
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m;
  long k, sum = 0;
  vector<int> a(200000, 1000000001), b(200000, 1000000001);
  cin >> n >> m >> k;
  rep(i, n) { cin >> a[i]; }
  rep(i, m) { cin >> b[i]; }
  int ac = 0, bc = 0;
  while (sum <= k) {
    if (a[ac] <= b[bc]) {
      sum += a[ac];
      ac++;
    } else {
      sum += b[bc];
      bc++;
    }
  }
  cout << ac + bc - 1 << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 200010;
ll a[N], b[N];
int n, m;
ll k;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int res = 0;
  cin >> n >> m >> k;
  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++) // 这里i一定要从0开始循环要不然会漏掉不在a数组中选数的情况
  {
    while (j && a[i] > k - b[j])
      j--;
    if (a[i] <= k - b[j])
      res = max(res, i + j);
  }
  cout << res << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int a[1000009], b[1000009];
int main() {
  int ans = 0;
  int n, m, s;
  cin >> n >> m >> s;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= m; i++)
    cin >> b[i];
  int a1 = 1, b1 = 1;
  while (s >= 0) {
    if (a[a1] > b[b1]) {
      if (s - b[b1] >= 0)
        ans++, s = s - b[b1++];
      else {
        cout << ans << endl;
        break;
      }
    } else {
      if (s - a[a1] >= 0)
        ans++, s = s - a[a1++];
      else {
        cout << ans << endl;
        break;
      }
    }
  }
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
long long a[200001], b[200001];
int main(void) {
  int n, m, k, ans = 0;
  cin >> n >> m >> k;
  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; i <= n; i++) {
    if (a[i] > k)
      break;
    int ok = 0, ng = m + 1;
    while (ok + 1 < ng) {
      int mid = (ok + ng) / 2;
      if (a[i] + b[mid] <= k)
        ok = mid;
      else
        ng = mid;
    }
    ans = max(ans, i + ok);
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int n, m, k, ans = 0;
  cin >> n >> m >> k;
  vector<long long> a(n + 1, 0), b(n + 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; i <= n; i++) {
    if (a[i] > k)
      break;
    int ok = 0, ng = m + 1;
    while (ok + 1 < ng) {
      int mid = (ok + ng) / 2;
      if (a[i] + b[mid] <= k)
        ok = mid;
      else
        ng = mid;
    }
    ans = max(ans, i + ok);
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define maxn 500005
#define inf int(21e8)
#define mod int(1e9 + 7)
#define db double
#define ll long long
#define si stack<int>
#define qi queue<int>
#define vi vector<int>
#define pi pair<int, int>
#define pq priority_queue<int, vector<int>, greater<int>>
using namespace std;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  for (; b; b >>= 1)
    res = (res * ((b & 1) ? a : 1)) % mod, a = a * a % mod;
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(a, b) : a; }
ll a[500005], b[500005];
ll sa[500005], sb[500005];
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i], sa[i] = sa[i - 1] + a[i];
  for (int i = 1; i <= m; i++)
    cin >> b[i], sb[i] = sb[i - 1] + b[i];
  int now = m, ans = 0;
  for (int i = 0; i <= n; i++) {
    while (sa[i] + sb[now] > k && now > 0)
      now--;
    if (sa[i] + sb[now] <= k)
      ans = max(ans, i + now);
  }
  cout << ans << endl;
  system("pause");
  return 0;
}

Error: 0
sh: 1: pause: not found


Fixed submission:

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define maxn 500005
#define inf int(21e8)
#define mod int(1e9 + 7)
#define db double
#define ll long long
#define si stack<int>
#define qi queue<int>
#define vi vector<int>
#define pi pair<int, int>
#define pq priority_queue<int, vector<int>, greater<int>>
using namespace std;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  for (; b; b >>= 1)
    res = (res * ((b & 1) ? a : 1)) % mod, a = a * a % mod;
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(a, b) : a; }
ll a[500005], b[500005];
ll sa[500005], sb[500005];
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i], sa[i] = sa[i - 1] + a[i];
  for (int i = 1; i <= m; i++)
    cin >> b[i], sb[i] = sb[i - 1] + b[i];
  int now = 1, ans = 0;
  for (int i = n; i >= 1; i--) {
    while (sa[i] + sb[now] <= k && now <= m)
      now++;
    now--;
    ans = max(ans, i + now);
  }
  cout << ans << endl;
  system("pause");
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long a[200005], b[200005], suma[200005], sumb[200005];
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  suma[0] = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    suma[i] = a[i] + suma[i - 1];
  }
  sumb[0] = 0;
  for (int i = 1; i <= m; i++) {
    scanf("%lld", &b[i]);
    sumb[i] = b[i] + sumb[i - 1];
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (k - suma[i] < 0) {
      break;
    }
    int j = upper_bound(sumb, sumb + m + 1, k - suma[i]) - sumb;
    ans = max(ans, i + j - 1);
  }
  printf("%d\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;
int n, m, k, maxs = 0;
// xox,xoy,yox,yoy,lx,sumx,ly,sumy,
int a[2][200010];
int max(int a, int b) { return a > b ? a : b; }
void g(int x, int p1, int p2, int lx, int sumx) {
  if (sumx + a[x][p1] > k) {
    maxs = max(lx, maxs);
    // cout<<111<<endl;
    return;
  }
  if (sumx + a[x][p1] == k) {
    maxs = max(lx + 1, maxs);
    // cout<<111<<endl;
    return;
  }
  // cout<<111<<endl;
  lx++;
  sumx += a[x][p1];
  if (x == 0) {
    p1++;
    if (p1 < n)
      g(0, p1, p2, lx, sumx);
    if (p2 < m)
      g(1, p2, p1, lx, sumx);
  } else if (x == 1) {
    p1++;
    if (p2 < n)
      g(0, p2, p1, lx, sumx);
    if (p1 < m)
      g(1, p1, p2, lx, sumx);
  }
}

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

  maxs = 0;
  for (int i = 0; i < n; i++)
    cin >> a[0][i];
  for (int i = 0; i < m; i++)
    cin >> a[1][i];
  if (a[0][0] > k && a[1][0] > k) {
    cout << 0 << endl;
    return 0;
  } // continue;}

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

//
//  AAAAAB.cpp
//  my_programs
//
//  Created by Jiatuo Zou on 7/22/20.
//  Copyright © 2020 Jiatuo Zou. All rights reserved.
//

#include <iostream>

int main() {
  using namespace std;

  int n, m, k, f = 0, books = 0, ans = 0, f2 = 0;
  long long int ab[2][200000], prefixs_sum[2][200001] = {{0}};
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    cin >> ab[0][i];
    prefixs_sum[0][i + 1] += (ab[0][i] + prefixs_sum[0][i]);
    if (prefixs_sum[0][i + 1] > k && f2 == 0) {
      f = i;
      f2 = 1;
    }
  }
  if (prefixs_sum[0][n] <= k) {
    f = n;
  }
  books = f;
  ans = f;
  for (int i = 0; i < m; i++) {
    cin >> ab[1][i];
    prefixs_sum[1][i + 1] += (ab[1][i] + prefixs_sum[1][i]);
  }
  for (int i = f, j = 1; j <= m;) {
    if (prefixs_sum[1][j] > k) {
      break;
    }
    if (k - prefixs_sum[0][i] >= prefixs_sum[1][j]) {
      j++;
      books++;
    } else if (i > 0 && k - prefixs_sum[0][i] < prefixs_sum[1][j]) {
      i--;
      books--;
    }
    ans = max(ans, books);
  }
  cout << ans << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, k, m, cnt = 0, count = 0;
  cin >> n >> m >> k;
  queue<int> a;
  queue<int> b;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a.push(x);
  }
  for (int i = 0; i < m; ++i) {
    int y;
    cin >> y;
    b.push(y);
  }

  while (cnt <= k) {
    int x = a.front();
    int y = b.front();
    if (x >= y) {
      cnt += y;
      b.pop();
    } else {
      cnt += x;
      a.pop();
    }
    if (count == n + m)
      break;
    if (cnt <= k)
      count++;
  }
  cout << count;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2e5 + 50;
ll n, m, k, arr[N], brr[N];

int solve(ll val) {
  int low = 1, high = m, mid, x = 0;
  while (low <= high) {
    mid = low + (high - low) / 2;
    if (brr[mid] <= val) {
      x = mid;
      low = mid + 1;
    } else
      high = mid - 1;
  }
  return x;
}

int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    arr[i] += arr[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    cin >> brr[i];
    brr[i] += brr[i - 1];
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (arr[i] > k)
      break;
    ans = max(ans, solve(k - arr[i]) + i);
  }
  cout << ans;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int y, x, m, sum = 0;
  bool flag1 = true, flag2 = true;
  cin >> x >> y >> m;
  stack<int> st;
  stack<int> st1;
  int arr[x];
  int arr1[y];
  for (int i = 0; i < x; i++) {
    cin >> arr[i];
  }
  for (int i = x - 1; i >= 0; i--) {
    st.push(arr[i]);
  }
  for (int i = 0; i < y; i++) {
    cin >> arr1[i];
  }
  for (int i = y - 1; i >= 0; i--) {
    st1.push(arr1[i]);
  }
  int z = x + y;
  for (int i = 0; i <= z; i++) {
    if (st.top() <= st1.top() && m - st.top() >= 0 && flag1 == true) {
      m -= st.top();
      if (st.size()) {
        st.pop();
      } else {
        flag1 = false;
      }
      sum++;
    } else if (st.top() >= st1.top() && m - st1.top() >= 0 && flag2 == true) {
      m -= st1.top();
      if (st1.size()) {
        st1.pop();
      } else {
        flag2 = false;
      }
      sum++;
    }
  }
  cout << sum;
}