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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define MP make_pair
#define EACH(i, c) for (auto i : c)
#define SORT(c) sort((c).begin(), (c).end())

#define ALL(a) (a).begin(), (a).end()

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];

  LL a = 0, b = 0;
  REP(j, M) b += B[j];
  LL j = M;
  LL ret = 0;
  REP(i, N + 1) {
    if (0 < i)
      a += A[i - 1];
    while (0 < j && K < a + b) {
      b -= B[j - 1];
      j--;
    }
    if (a + b <= K)
      ret = max(i + j, ret);
  }

  cout << ret << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define MP make_pair
#define EACH(i, c) for (auto i : c)
#define SORT(c) sort((c).begin(), (c).end())

#define ALL(a) (a).begin(), (a).end()

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

  LL N, M, K;
  cin >> N >> M >> K;

  vector<LL> A(N), B(N);
  REP(i, N) cin >> A[i];
  REP(i, M) cin >> B[i];

  LL a = 0, b = 0;
  REP(j, M) b += B[j];
  LL j = M;
  LL ret = 0;
  REP(i, N + 1) {
    if (0 < i)
      a += A[i - 1];
    while (0 < j && K < a + b) {
      b -= B[j - 1];
      j--;
    }
    if (a + b <= K)
      ret = max(i + j, ret);
  }

  cout << ret << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define tcase                                                                  \\
  int _;                                                                       \\
  cin >> _;                                                                    \\
  while (_--)
const int MAX = 1e6;

int n, m, k;
ll a[MAX], b[MAX];
int ans;

void solve() {
  cin >> n >> m >> k;
  a[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];
  }
  ans = 0;
  int j = m;
  for (int i = 0; i <= n; i++) {
    if (a[i] > k)
      break;
    for (; a[i] + b[j] > k; j--)
      ;
    ans = max(ans, i + j);
  }
  cout << ans << "\\n";
}

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

  solve();

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define tcase                                                                  \\
  int _;                                                                       \\
  cin >> _;                                                                    \\
  while (_--)
const int MAX = 1e6;

int n, m, k;
int a[MAX], b[MAX];

void solve() {
  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 ans = 0;
  int i = 0, j = 0;
  while (i < n || j < m) {
    if (i < n && j < m) {
      if (a[i] < b[i]) {
        k -= a[j];
        i++;
      } else {
        k -= b[j];
        j++;
      }
    } else if (i < n) {
      k -= a[i];
      i++;
    } else if (j < m) {
      j -= b[j];
      j++;
    }
    if (k < 0)
      break;
    ans++;
  }
  cout << ans << "\\n";
}

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

  solve();

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

#include <algorithm>
#include <ciso646>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

// 解説ac

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> aa(n);
  vector<int> bb(m);
  rep(i, n) cin >> aa[i];
  rep(i, m) cin >> bb[i];
  ll tota = 0;
  rep(i, m) tota += bb[i];
  int j = m;
  int ans = 0;
  rep(i, n + 1) { // iがaaの本の数
    while (tota > k and j > 0) {
      --j; // 読むbを減らしていく
      tota -= bb[j];
    }
    if (tota > k)
      break;
    ans = max(ans, i + j);
    if (i == n)
      break;
    tota += aa[i];
  }
  cout << ans << endl;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <ciso646>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

int main() {
  int n, m;
  ll k;
  cin >> n >> m >> k;
  ll sum = 0;
  vector<ll> aa(n);
  vector<ll> bb(m);
  rep(i, n) cin >> aa[i];
  rep(i, m) cin >> bb[i];
  ll M = min(n, m);
  ll N = max(n, m);
  int cnt = 0;
  rep(i, M) {
    if (sum >= k - min(aa[0], bb[0])) {
      cout << cnt;
      return 0;
    }
    if (aa[0] < bb[0]) {
      sum += aa[i];
      if (i != N - 1)
        aa[0] = aa[i + 1];
      cnt++;
    } else if (aa[0] >= bb[0]) {
      sum += bb[0];
      if (i != N - 1)
        bb[0] = bb[i + 1];
      cnt++;
    }
    for (int i = M; i < N; i++) {
      if (sum >= k - min(aa[0], bb[0])) {
        cout << cnt;
        return 0;
      }

      if (N == m) {
        sum += bb[0];
        if (i != N - 1)
          bb[0] = bb[i + 1];
        cnt++;
      } else {
        sum += aa[0];
        if (i != N - 1)
          bb[0] = bb[i + 1];
        cnt++;
      }
    }
  }

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

#include <bits/stdc++.h>
#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 MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

  ll A[N], B[M], a[N + 1], b[M + 1];
  a[0] = 0;
  b[0] = 0;
  REP(i, N) {
    cin >> A[i];
    a[i + 1] = a[i] + A[i];
  }
  REP(i, M) {
    cin >> B[i];
    b[i + 1] = b[i] + B[i];
  }

  ll j = M, ans = 0;
  REP(i, N + 1) {
    if (a[i] > K) {
      break;
    }

    while (b[j] > K - a[i]) {
      j--;
    }

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

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#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 MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

  ll A[N], B[M];
  REP(i, N) { cin >> A[i]; }
  REP(i, M) { cin >> B[i]; }

  ll ans = 0, res = 0, pos = 0, temp = 0, temp_j = 0;
  REP(i, N) {
    res += A[i];
    if (res > K) {
      break;
    }
    temp = res;
    REP(j, M) {
      temp += B[j];
      temp_j = j + 1;
      if (temp > K) {
        temp_j--;
        break;
      }
    }
    pos = i + 1 + temp_j;

    if (ans < pos) {
      ans = pos;
    }
  }

  temp = 0;
  pos = 0;
  REP(i, M) {
    temp += B[i];
    pos++;
    if (temp > K) {
      break;
    }
  }

  if (pos - 1 > ans)
    ans = pos - 1;
  cout << ans << endl;

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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  ll i1 = 0, i2 = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (i) {
      a[i] += a[i - 1];
    }
    if (a[i] <= k) {
      i1 = i + 1;
    }
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
    if (i) {
      b[i] += b[i - 1];
    }
    if (b[i] <= k) {
      i2 = i + 1;
    }
  }

  ll ans = max(i1, i2);

  ll i = 0, j = i2 - 1;
  for (; i < i1; ++i) {
    while (a[i] + b[j] > k) {
      --j;
    }
    ans = max(ans, i + j + 2);
  }

  //    for(ll i = i1-1; i >= 0; --i) {
  //        ll st = 0, dr = i2-1, mij;
  //        ll index = -2;
  //        while(st < dr) {
  //            mij = (st + dr) / 2;
  //            if(a[i] + b[mij] <= k) {
  //                st = mij+1;
  //                index = mij;
  //            }
  //            else if(a[i] + b[mij] > k) {
  //                dr = mij;
  //            }
  //        }
  //        if(index+1 < i2 && a[i] + b[index+1] <= k) {
  //            ++index;
  //        }
  //        ans = max(ans, i + index + 2);
  //    }

  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  ll i1 = 0, i2 = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (i) {
      a[i] += a[i - 1];
    }
    if (a[i] <= k) {
      i1 = i + 1;
    }
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
    if (i) {
      b[i] += b[i - 1];
    }
    if (b[i] <= k) {
      i2 = i + 1;
    }
  }

  ll ans = max(i1, i2);

  for (ll i = i1 - 1; i >= 0; --i) {
    ll j = 0;
    while (a[i] + b[j] <= k && j < i2) {
      ans = max(ans, i + j + 2);
      ++j;
    }
  }

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

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

int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  vector<ll> A(N + 1, 0), B(M + 1, 0);
  ll a, b;
  for (ll i = 1; i < N + 1; i++) {
    cin >> a;
    A[i] = a + A[i - 1];
  }
  for (ll i = 1; i < M + 1; i++) {
    cin >> b;
    B[i] = b + B[i - 1];
  }

  // vector<ll> c(N);
  ll maxj = M;
  ll ans = 0;
  for (ll i = 0; i < N + 1; i++) {
    if (A[i] > K) {
      break;
    }
    for (ll j = maxj; j >= 0; j--) {
      if (A[i] + B[j] <= K) {
        ans = max(ans, i + j);
        maxj = j;
        break;
      }
    }
  }

  cout << ans << endl;
}

Error: WA

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> A(N), B(M);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (ll i = 0; i < M; i++) {
    cin >> B[i];
  }
  for (ll i = 1; i < N; i++) {
    A[i] += A[i - 1];
  }
  for (ll i = 1; i < N; i++) {
    B[i] += B[i - 1];
  }

  // vector<ll> c(N);
  ll maxj = M - 1;
  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    for (ll j = maxj; j >= 0; j--) {
      if (A[i] + B[j] <= K) {
        ans = max(ans, i + j + 2);
        maxj = j;
        break;
      }
    }
  }

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

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

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1), b(m + 1);
  int p = n, q = m;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.at(i + 1) = a.at(i) + x;
    if (a.at(i + 1) > k)
      p = i;
  }
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    b.at(i + 1) = b.at(i) + x;
    if (b.at(i + 1) > k)
      q = i;
  }
  int ans = 0;
  for (int i = 0; i <= p; i++) {
    while (q >= 0) {
      if (a.at(i) + b.at(q) <= k) {
        ans = max(i + q, ans);
        break;
      } else
        q--;
    }
  }
  cout << ans << endl;
}


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;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
using graph = vector<vector<int>>;

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, k;
  cin >> n >> m >> k;
  vector<ll> A(n + 1), B(m + 1);
  rep(i, n) {
    int a;
    cin >> a;
    A.at(i + 1) = A.at(i) + a;
  }
  rep(i, m) {
    int b;
    cin >> b;
    B.at(i + 1) = B.at(i) + b;
  }
  ll sum = 0;
  ll ans = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      ll tmp = A.at(i) - A.at(0) + B.at(j) - B.at(0);
      if (tmp <= k) {
        sum = i + j;
        ans = max(ans, sum);
      }
    }
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#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 + 5] = {0}, b[m + 5] = {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;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> book;
  int a, b, c;
  cin >> a >> b >> c;
  for (int i = 0; i < a * 2; i += 2) {
    int k;
    cin >> k;
    book.push_back(k);
  }
  for (int i = 1; i < b * 2; i += 2) {
    int k;
    cin >> k;
    book.push_back(k);
  }
  int ma = 0, ans = 0;
  for (int i = 0; i < a + b; i++) {
    ma += min(book[0], book[1]);
    if (book[0] < book[1]) {
      book.erase(book.begin());
    } else {
      book.erase(book.begin() + 1);
    }
    if (ma > c) {
      cout << ans;
      return 0;
    }
    ans++;
  }
  cout << ans;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
// 2의 제곱수 판정
#define POW2(X) (X) == ((X) & (-(X)))

// 기본설정
typedef long long ll;
using namespace std;
int dirx[4] = {1, 0, -1, 0};
int diry[4] = {0, 1, 0, -1};

// 전역변수
ll n, m, k, ans = 0;
vector<ll> a, b;

int main(void) {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);

  cin >> n >> m >> k;
  a.push_back(0);
  b.push_back(0);
  for (int i = 0; i < n; i++) {
    ll book;
    cin >> book;
    a.push_back(a[i] + book);
  }
  for (int i = 0; i < m; i++) {
    ll book;
    cin >> book;
    b.push_back(b[i] + book);
  }

  int le = 0, ri = n + m;
  while (le <= ri) {
    // 총 확인할 책의 권수
    int mid = (le + ri) / 2;
    // 만족하는지
    bool flag = false;
    // 각각의 책상에서 볼 책의 권수
    for (int ab = 0; ab <= mid; ab++) {
      int bb = mid - ab;
      if (n < ab || m < bb)
        continue;
      if (a[ab] + b[bb] <= k) {
        flag = true;
        break;
      }
    }
    if (flag) {
      ans = max(ans, (ll)mid);
      le = mid + 1;
    } else {
      ri = mid - 1;
    }
  }

  cout << ans;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// 2의 제곱수 판정
#define POW2(X) (X) == ((X) & (-(X)))

// 기본설정
typedef long long ll;
using namespace std;
int dirx[4] = {1, 0, -1, 0};
int diry[4] = {0, 1, 0, -1};

// 전역변수
int n, m, k;
vector<int> a, b;

ll solve(int da, int db, ll cnt) {
  ll c = cnt;

  // a에서 책을 읽을 경우
  if (da < n && k - a[da] >= 0) {
    k -= a[da];
    cnt = max(cnt, solve(da + 1, db, c + 1));
    k += a[da];
  }

  // b에서 책을 읽을 경우
  if (db < m && k - b[db] >= 0) {
    k -= b[db];
    cnt = max(cnt, solve(da, db + 1, c + 1));
    k += b[db];
  }

  return cnt;
}

int main(void) {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);

  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    int book;
    cin >> book;
    a.push_back(book);
  }
  for (int i = 0; i < m; i++) {
    int book;
    cin >> book;
    b.push_back(book);
  }

  cout << solve(0, 0, 0);

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
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;
}
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;

void solve() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> A(n + 2, 0), B(m + 2, 0);
  rep(i, n) {
    ll a;
    cin >> a;
    A[i + 1] = A[i] + a;
  }
  A[0] = 0;
  A[n + 1] = LINF;
  rep(i, m) {
    ll a;
    cin >> a;
    B[i + 1] = B[i] + a;
  }
  B[0] = 0;
  B[m + 1] = LINF;
  int ans = 0;
  rep(i, n + 1) {
    if (k - A[i] < 0)
      break;
    chmax(ans, i + (int)(upper_bound(all(B), k - A[i]) - B.begin() - 1));
  }
  cout << ans << endl;
}

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
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;
}
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;

void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<ll> A(n + 2, 0), B(m + 2, 0);
  rep(i, n) {
    ll a;
    cin >> a;
    A[i + 1] = A[i] + a;
  }
  A[0] = 0;
  A[n + 1] = LINF;
  rep(i, n) {
    ll a;
    cin >> a;
    B[i + 1] = B[i] + a;
  }
  B[0] = 0;
  B[m + 1] = LINF;
  int ans = 0;
  rep(i, n + 1) {
    if (k - A[i] < 0)
      continue;
    chmax(ans, i + (int)(upper_bound(all(B), k - A[i]) - B.begin() - 1));
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
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;
}
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;

void solve() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> A(n + 2, 0), B(m + 2, 0);
  rep(i, n) {
    ll a;
    cin >> a;
    A[i + 1] = A[i] + a;
  }
  A[0] = 0;
  A[n + 1] = LINF;
  rep(i, m) {
    ll a;
    cin >> a;
    B[i + 1] = B[i] + a;
  }
  B[0] = 0;
  B[m + 1] = LINF;
  int ans = 0;
  int j = m;
  rep(i, n + 1) {
    while (A[i] + B[j] > k) {
      j--;
      if (j < 0) {
        break;
      }
    }
    if (j < 0)
      break;
    chmax(ans, i + j);
  }
  cout << ans << endl;
}

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

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
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;
}
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;

void solve() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> A(n + 2, 0), B(m + 2, 0);
  rep(i, n) {
    ll a;
    cin >> a;
    A[i + 1] = A[i] + a;
  }
  A[0] = 0;
  A[n + 1] = LINF;
  rep(i, m) {
    ll a;
    cin >> a;
    B[i + 1] = B[i] + a;
  }
  B[0] = 0;
  B[m + 1] = LINF;
  int ans = 0;
  int j = m;
  rep(i, n + 1) {
    while (A[i] + B[j] > k)
      j--;
    if (j < 0)
      break;
    chmax(ans, i + j);
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m;
  long k;
  cin >> n >> m >> k;
  long t;
  long a[n + 1], b[m + 1];
  a[0] = 0;
  b[0] = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> t;
    a[i] = a[i - 1] + t;
  }
  for (int i = 1; i <= m; ++i) {
    cin >> t;
    b[i] = b[i - 1] + t;
  }
  int count = 0;
  int sj, ej;
  ej = m + 1;
  for (int i = 0; i <= n; ++i) {
    sj = (count - i > 0) ? count - i : 0;
    for (int j = sj; j < ej; ++j) {
      if (a[i] + b[j] <= k) {
        count = i + j;
      } else {
        ej = j;
        break;
      }
    }
    // cout << count << endl;
  }
  cout << count << endl;
}


Error: 0

Fixed submission:

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

int main() {
  long n, m, k;
  cin >> n >> m >> k;
  queue<long> a, b;
  long t;
  for (int i = 0; i < n; ++i) {
    cin >> t;
    a.push(t);
  }
  for (int i = 0; i < m; ++i) {
    cin >> t;
    b.push(t);
  }
  int count = 0;
  for (int i = 0; i < (n + m); ++i) {
    if (!a.empty() and a.front() <= b.front()) {
      k -= a.front();
      a.pop();
    } else {
      k -= b.front();
      b.pop();
    }
    if (k < 0)
      break;
    else if (k == 0) {
      count++;
      break;
    } else
      count++;
  }
  cout << count << endl;
}