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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define vv vector<ll>
#define fr(i, x) for (int i = 0; i < x; i++)
int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, -1, 1, 0};

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {

  if (a.first == b.first)
    return a.second < b.second;
  return (a.first < b.first);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, x, m, r, cnt = 0, k, y;

  cin >> n >> m >> k;
  vector<ll> a, b;
  a.push_back(0);
  b.push_back(0);
  for (ll i = 1; i <= n; i++) {
    cin >> x;
    a.push_back(x + a[i - 1]);
  }
  for (int i = 1; i <= m; i++) {
    cin >> x;
    b.push_back(x + b[i - 1]);
  }
  ll res = 0;
  for (int i = 0; i <= n; i++) {
    ll t = 0;
    auto it = a.begin();
    if (a[i] <= k) {
      it = upper_bound(b.begin(), b.end(), k - a[i]);
      t += (i + (it - b.begin() - 1));
      // t = max(t,(i+(it-b.begin()-1)));
    }
    res = max(t, res);
  }
  cout << res << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define fr for (int i = 0; i < n; i++)
#define pb push_back
void printVector(vector<char> x) {
  for (auto i : x) {
    cout << i << " ";
  }
  cout << endl;
}

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

  int n, m, k, x;
  cin >> n >> m >> k;
  vector<int> a, b;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
  }
  for (int i = 0; i < m; i++) {
    cin >> x;
    b.push_back(x);
  }
  int pointA = 0, pointB = 0, _count = 0, sum = 0;
  while (sum <= k) {

    if (pointA > n)
      sum += b[pointB];
    if (pointB > m)
      sum += a[pointA];
    if (a[pointA] > b[pointB]) {
      sum += b[pointB];
      pointB++;
    } else {
      sum += a[pointA];
      pointA++;
    }
    // cout << sum << endl;
    _count++;
  }
  cout << _count - 1 << endl;

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


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")

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

#define FIO                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(nullptr);                                                            \\
  cout.tie(nullptr);
typedef long long ll;

int32_t main() {
  FIO;
  ll n, m, k, temp;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  for (int i = 0; i < n; ++i) {
    if (!i)
      cin >> a[i];
    else {
      cin >> temp;
      a[i] = a[i - 1] + temp;
    }
  }
  for (int i = 0; i < m; ++i) {
    if (!i)
      cin >> b[i];
    else {
      cin >> temp;
      b[i] = b[i - 1] + temp;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (k < a[i])
      break;
    int p = upper_bound(b.begin(), b.end(), k - a[i]) - b.begin();
    ans = max(ans, i + 1 + p);
  }
  for (int i = 0; i < m; ++i) {
    if (k < b[i])
      break;
    int p = upper_bound(a.begin(), a.end(), k - b[i]) - a.begin();
    ans = max(ans, i + 1 + p);
  }
  cout << ans << '\\n';
}


Error: 0

Fixed submission:


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")

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

#define FIO                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(nullptr);                                                            \\
  cout.tie(nullptr);
typedef long long ll;

int32_t main() {
  FIO;
  ll n, m, k, temp;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  for (int i = 0; i < n; ++i) {
    if (!i)
      cin >> a[i];
    else {
      cin >> temp;
      a[i] = a[i - 1] + temp;
    }
  }
  for (int i = 0; i < m; ++i) {
    if (!i)
      cin >> b[i];
    else {
      cin >> temp;
      b[i] = b[i - 1] + temp;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ll diff = k - a[i];
    if (diff < 0)
      break;
    else {
      int p = 0;
      for (int i = m / 2; i >= 1; i /= 2) {
        while (i + p < m && a[p + i] <= diff)
          p += i;
      }
      ans = max(ans, i + p + 2);
    }
  }
  cout << ans << '\\n';
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<ll, int> p;

#define MOD 1000000007

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

  int N, M;
  ll K;

  cin >> N >> M >> K;

  vector<ll> A(N);
  vector<ll> B(M);

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

  vector<ll> as(N + 1);
  vector<ll> bs(M + 1);

  for (int i = 1; i <= N; i++)
    as[i] = A[i - 1] + as[i - 1];
  for (int i = 1; i <= M; i++)
    bs[i] = B[i - 1] + bs[i - 1];

  int ans = 0;

  for (int i = 0; i <= N; i++) {
    if (K - as[i] < 0)
      break;
    ll r = K - as[i];
    int x = upper_bound(bs.begin(), bs.end(), r) - bs.begin();
    ans = max(ans, i + x - 1);
  }

  for (int i = 0; i <= M; i++) {
    if (K - bs[i] < 0)
      break;
    ll r = K - bs[i];
    int x = upper_bound(as.begin(), as.end(), r) - as.begin();
    ans = max(ans, i + x - 1);
  }

  if (as[N] + bs[M] <= K)
    ans = N + M;

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<ll, int> p;

#define MOD 1000000007

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

  int N, M;
  ll K;

  cin >> N >> M >> K;

  vector<ll> A(N);
  vector<ll> B(M);

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

  vector<ll> as(N + 1);
  vector<ll> bs(M + 1);

  for (int i = 1; i <= N; i++)
    as[i] = A[i - 1] + as[i - 1];
  for (int i = 1; i <= M; i++)
    bs[i] = B[i - 1] + bs[i - 1];

  int ans = 0;

  for (int i = 0; i <= N; i++) {
    if (K - as[i] < 0)
      break;
    ll r = K - as[i];
    int x = upper_bound(bs.begin(), bs.end(), r) - bs.begin();
    ans = max(ans, i + x - 1);
  }

  for (int i = 0; i <= N; i++) {
    if (K - bs[i] < 0)
      break;
    ll r = K - bs[i];
    int x = upper_bound(as.begin(), as.end(), r) - as.begin();
    ans = max(ans, i + x - 1);
  }

  if (as[N] + bs[N] <= K)
    ans = N + M;

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


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = 1LL << 60;

// 単調増加なので二分探索でできる
// 以下は尺取法を行っている
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  vector<int> b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];

  ll t = 0;
  rep(i, m) t += b[i];

  int j = m;
  int ans = 0;
  // i(A側)とj(B側)の2つのカーソルを追う
  rep(i, n + 1) {
    // 合計時間tがkを超えていたら１つずつ諦める
    while (j > 0 && t > k) {
      --j;
      t -= b[j];
    }
    // もう諦められる本がない(j=0)かつt>kならbreak
    if (t > k)
      break;
    ans = max(ans, i + j);
    // 配列外参照を防ぐためにbreakで誤魔化している
    if (i == n)
      break;
    t += a[i];
  }

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

Error: TLE

Fixed submission:


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = 1LL << 60;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  vector<ll> b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];

  int ans = 0;
  ll acount = 0;
  ll bcount = 0;
  while (true) {
    if (acount == n && bcount == m) {
      cout << n + m << endl;
      return 0;
    } else if (a[acount] <= b[acount] || bcount == m) {
      k -= a[acount];
      if (k < 0)
        break;
      acount++;
    } else if (a[acount] > b[bcount] || acount == n) {
      k -= b[bcount];
      if (k < 0)
        break;
      bcount++;
    }
  }
  cout << acount + bcount << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long n, m, k;
  cin >> n >> m >> k;
  vector<long long> a(n + 1), b(m + 1);
  int ans = 0, ar, br = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a.at(i);
    a.at(i) += a.at(i - 1);
    if (a.at(i) <= k)
      ar = i;
  }
  for (int i = 1; i <= m; i++) {
    cin >> b.at(i);
    b.at(i) += b.at(i - 1);
  }

  for (int i = ar; i >= 0; i--) {
    for (int j = br; j <= m; j++) {
      if (a.at(i) + b.at(j) <= k) {
        br = j;
        ans = max(ans, i + br);
      } else
        break;
    }
    if (br == m)
      break;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
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; i++) {
    cin >> a.at(i);
    a.at(i) += a.at(i - 1);
  }
  for (int i = 1; i <= m; i++) {
    cin >> b.at(i);
    b.at(i) += b.at(i - 1);
  }

  int ans = 0, cb = 0;
  for (int i = n; i >= 0; i--) {
    if (a.at(i) > k)
      continue;
    for (int j = cb; j <= m; j++) {
      if (a.at(i) + b.at(j) > k)
        continue;
      ans = max(ans, i + j);
      cb = j;
    }
  }

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

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

int main() {
  long long N, M, K;
  long long zikan = 0;
  long long count1 = 0;
  long long count2 = 0;
  cin >> N >> M >> K;

  bool seigo1 = false;
  bool seigo2 = false;

  vector<long long> AA(300000);
  vector<long long> BB(300000);

  for (long long i = 0; i < N; i++) {
    cin >> AA.at(i);
    if (zikan + AA.at(i) <= K && seigo1 == false) {
      zikan += AA.at(i);
      count1++;
    } else {
      seigo1 = true;
    }
  }

  for (long long j = 0; j < M; j++) {
    cin >> BB.at(j);
    if (zikan + BB.at(j) <= K && seigo2 == false) {
      zikan += BB.at(j);
      count2++;
    } else {
      seigo2 = true;
    }
  }

  long long total = count1 + count2;

  long long kotei = count1;

  for (long long k = 0; k < kotei; k++) {
    count1--;
    zikan -= AA.at(count1);

    while (1) {
      if (count2 == M) {
        break;
      }
      if (zikan + BB.at(count2) <= K) {
        zikan += BB.at(count2);
        count2++;
      } else {
        break;
      }
    }

    if (count1 + count2 > total) {
      total = count1 + count2;
    }
  }
  cout << total;
}


Error: WA

Fixed submission:

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

int main() {
  long long N, M, K;
  long long zikan = 0;
  long long count1 = 0;
  long long count2 = 0;
  cin >> N >> M >> K;

  vector<long long> AA(300000);
  vector<long long> BB(300000);

  for (long long i = 0; i < N; i++) {
    long long A;
    cin >> A;
    AA.at(i) = A;
    if (zikan + A <= K) {
      zikan += A;
      count1++;
    }
  }
  for (long long j = 0; j < M; j++) {
    long long B;
    cin >> B;
    BB.at(j) = B;
    if (zikan + B <= K) {
      zikan += B;
      count2++;
    }
  }

  long long total = count1 + count2;

  for (long long k = 0; k < count1; k++) {
    count1--;
    zikan -= AA.at(count1 - 1);
    while (1) {
      if (count2 >= M) {
        break;
      }
      if (zikan + BB.at(count2) <= K) {
        zikan += BB.at(count2);
        count2++;

      } else {
        break;
      }
    }
    if (count1 + count2 > total) {
      total = count1 + count2;
    }
  }
  cout << total;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

void solve() {
  int n, m;
  ll k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  forn(i, n) cin >> a[i];
  vector<ll> b(m);
  forn(i, m) cin >> b[i];
  int i, j;
  ll suma = 0;
  for (i = 0; i < n; i++)
    suma += a[i];
  for (i = n - 1; i >= 0; i--) {
    if (suma <= k) {
      break;
    }
    suma -= a[i];
  }
  int ans = i + 1;
  int max_ans = ans;
  j = 0;
  while (j < m) {
    if (suma + b[j] <= k) {
      ans++;
      suma += b[j];
      j++;
    } else {
      max_ans = max(max_ans, ans);
      if (i >= 0) {
        suma -= a[i];
        i--;
        ans--;
      } else {
        break;
      }
    }
  }
  max_ans = max(max_ans, ans);
  cout << max_ans << endl;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
//     freopen("output.txt","w",stdout);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

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

void solve() {
  int n, m;
  ll k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  forn(i, n) cin >> a[i];
  vector<ll> b(m);
  forn(i, m) cin >> b[i];
  ll min = 0;
  int i = 0, j = 0;
  int ans = 0;
  while (min < k && i < n && j < m) {
    if (a[i] <= b[j]) {
      ans++;
      min += a[i];
      i++;
    } else {
      ans++;
      min += b[j];
      j++;
    }
    // cout << min << endl;
  }
  // cout << min << endl;
  // cout << ans <<
  if (min == k) {
    cout << ans << endl;
    return;
  }
  if (min > k) {
    cout << ans - 1 << endl;
    return;
  }
  if (min < k) {
    while (i < n) {
      ans++;
      min += a[i];
      i++;
    }
    while (j < m) {
      ans++;
      min += a[j];
      j++;
    }
  }
  if (min > k) {
    ans--;
    cout << ans << endl;
    return;
  }
  cout << ans << endl;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
//     freopen("output.txt","w",stdout);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
}
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++)
#define Rep(i, n) for (long long i = 1; i < n; i++)
#define ll long long
#include <cmath>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define PI acos(-1)

ll ans = 0;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> b(m);
  rep(i, m) cin >> b[i];

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < n; i++)
#define Rep(i, n) for (long long i = 1; i < n; i++)
#define ll long long
#include <cmath>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define PI acos(-1)

ll ans = 0;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> b(m);
  rep(i, m) cin >> b[i];

  vector<ll> A = {0};
  rep(i, n) A.push_back(A[i] + a[i]);
  vector<ll> B = {0};
  rep(i, m) B.push_back(B[i] + b[i]);
  rep(i, A.size()) {
    if (k < A[i])
      break;
    else {
      for (ll l = B.size() - 1; 0 <= l; l--) {
        if (A[i] + B[l] <= k) {
          ans = max(ans, i + l);
          break;
        }
      }
    }
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#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);
  a[0] = 0;
  b[0] = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i + 1];
    a[i + 1] += a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i + 1];
    b[i + 1] += b[i];
  }
  int t;
  vector<int> c(0);
  for (int i = 0; i <= m; i++) {
    if (b[m - i] <= k) {
      c.push_back(m - i);
      t = i;
      break;
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = t; j <= m; j++) {
      if (a[i] + b[m - j] <= k) {
        c.push_back(m + i - j);
        t = j;
        break;
      }
    }
  }

  sort(c.begin(), c.end());
  reverse(c.begin(), c.end());
  cout << c[0] << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n + 1), b(m + 1);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < m; i++)
    cin >> b[i];
  a[n + 1] = 100000001;
  b[m + 1] = 100000001;

  int x = 0, y = 0;
  int ans = 0, c = 0;
  long long t = 0;
  while (1) {
    if (c == n + m)
      break;

    ans++;

    if (a[x] <= b[y]) {
      t += a[x];
      x++;

    }

    else {
      t += b[y];
      y++;
    }

    if (t > k) {
      ans--;
      break;
    }
    c++;
  }

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

#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  long long n, m, k;
  std::cin >> n >> m >> k;
  // long long  a[n+1], b[m+1];
  std::vector<long long> a(n + 1), b(m + 1);
  a[0] = 0;
  b[0] = 0;
  for (int i = 1; i < n + 1; i++)
    std::cin >> a[i];
  for (int i = 1; i < m + 1; i++)
    std::cin >> b[i];

  for (int i = 1; i < n + 1; i++)
    a[i] += a[i - 1];
  for (int i = 1; i < m + 1; i++)
    b[i] += b[i - 1];

  long long ans = 0, r = m;
  for (int i = 0; i < n + 1; i++) {
    if (a[i] > k)
      break;
    while (a[i] + b[r] > k)
      r--;
    ans = std::max({ans, i + r});
  }

  std::cout << ans;

  return 0;
}


Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  long long n, m, k;
  std::cin >> n >> m >> k;
  // long long  a[n+1], b[m+1];
  std::vector<long long> a{n + 1}, b{m + 1};
  a[0] = 0;
  b[0] = 0;
  for (int i = 1; i < n + 1; i++)
    std::cin >> a[i];
  for (int i = 1; i < m + 1; i++)
    std::cin >> b[i];

  for (int i = 1; i < n + 1; i++)
    a[i] += a[i - 1];
  for (int i = 1; i < m + 1; i++)
    b[i] += b[i - 1];

  long long ans = 0, r = m;
  for (int i = 0; i < n + 1; i++) {
    if (a[i] > k)
      break;
    while (a[i] + b[r] > k)
      r--;
    ans = std::max({ans, i + r});
  }

  std::cout << ans;

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

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

ll n, m, k;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  vector<ll> a(n);
  vector<ll> b(m);

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

  vector<ll> sumA(n + 1);
  vector<ll> sumB(m + 1);

  sumA[0] = 0;
  sumB[0] = 0;

  for (int i = 1; i <= n; i++) {
    sumA[i] = sumA[i - 1] + a[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    sumB[i] = sumB[i - 1] + b[i - 1];
  }

  ll res = 0;
  // solve
  for (int i = 0; i <= n; i++) {
    ll whatToFind = k - sumA[i];
    if (whatToFind < 0)
      continue;

    ll poz = upper_bound(sumB.begin(), sumB.end(), whatToFind) - sumB.begin();
    poz--;

    res = max(res, poz + i);
  }

  cout << res;
  return 0;
}

Error: WA

Fixed submission:

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

ll n, m, k;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  cin >> n >> m >> k;
  vector<ll> a(n + 1);
  for (ll i = 0; i < n; i++)
    cin >> a[i];

  vector<ll> b(m + 1);
  for (ll i = 0; i < n; i++)
    cin >> b[i];

  a[n] = 10e10;
  b[n] = 10e10;
  ll i = 0, j = 0;
  ll res = 0;
  while ((a[i] <= k || b[j] <= k)) {
    if (i < n && j < m) {
      if (a[i] > b[j]) {
        res++;
        k -= b[j++];
      } else {
        res++;
        k -= a[i++];
      }
    } else if (i < n) {
      res++;
      k -= a[i++];
    } else if (j < m) {
      res++;
      k -= b[j++];
    } else {
      break;
    }
  }
  cout << res;

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

// https://atcoder.jp/contests/abc172/tasks/abc172_c
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n, m, k;
  cin >> n >> m >> k;
  vector<long long> a(n + 1);
  vector<long long> b(m + 1);
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  for (long long i = 1; i <= m; i++) {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  long long ans = 0;
  long long i;
  for (i = 0; i <= n; i++) {
    if (k >= a[i]) {
      long long s = k - a[i];
      long long st = 0, en = m;
      while (st < en) {
        long long mi = (st + en) / 2;
        if (s > b[mi]) {
          st = mi + 1;
        } else if (s < b[mi]) {
          en = mi - 1;
        } else {
          break;
        }
      }
      if (b[st] > s) {
        ans = max(ans, i + st - 1);
      } else {
        ans = max(ans, i + st);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

// https://atcoder.jp/contests/abc172/tasks/abc172_c
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n, m, k;
  cin >> n >> m >> k;
  vector<long long> a(n + 1);
  vector<long long> b(m + 1);
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  for (long long i = 1; i <= m; i++) {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  long long ans = 0;
  long long i;
  for (i = 0; i <= n; i++) {
    long long searchfor = k - a[i];
    if (searchfor >= 0) {
      long long start = 0, end = m;
      long long mid = (start + end) / 2;
      bool found = false;
      do {
        mid = (start + end) / 2;
        if (searchfor > b[mid]) {
          start = mid + 1;
        } else if (searchfor <= b[mid]) {
          end = mid - 1;
        }
        found = true;
      } while (start <= end && start <= m && end >= 0);
      if (start > m) {
        --start;
      }
      if (end < 0) {
        ++end;
      }
      if (found) {
        if (searchfor >= a[start]) {
          ans = max(ans, i + start);
        } else {
          ans = max(ans, i + start - 1);
        }
      }
    }
  }
  cout << ans << endl;
  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(1, 0);
  vector<ll> b(1, 0);
  int as, bs;
  for (int i = 1; i < n + 1; i++) {
    cin >> as;
    a.push_back(as);
    a[i] = a[i] + a[i - 1];
  }
  for (int i = 1; i < m + 1; i++) {
    cin >> bs;
    b.push_back(bs);
    b[i] = b[i] + b[i - 1];
  }

  int tot = 0;
  int bnum = m;
  for (int i = 0; i < n + 1; i++) {
    if (a[i] > k)
      break;
    while (b[bnum] > k - a[i])
      bnum--;
    tot = max(tot, i + bnum);
  }
  cout << tot;
}


Error: WA

Fixed submission:

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

int main() {
  int m, n;
  ll k;
  ll a, b;
  cin >> m >> n >> k;
  vector<ll> as, bs;
  for (int i = 0; i < m; i++) {
    cin >> a;
    as.push_back(a);
  }
  for (int i = 0; i < n; i++) {
    cin >> b;
    bs.push_back(b);
  }
  ll total = 0;
  int books = 0;
  while (total < k) {
    if (as[0] < bs[0]) {
      total += as[0];
      as.erase(as.begin());
    } else {
      total += bs[0];
      bs.erase(bs.begin());
    }
    books++;
  }
  cout << books - 1;
}