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

#include <bits/stdc++.h>
#define l_ength size
const int inf = (1 << 30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  vector<ll> b(m);
  for (auto &t : a)
    cin >> t;
  for (auto &t : b)
    cin >> t;
  vector<ll> asum(n + 1);
  vector<ll> bsum(m + 1);
  int ans = 0;
  for (int i = 0; i < n; ++i)
    asum[i + 1] = asum[i] + a[i];
  for (int i = 0; i < m; ++i)
    bsum[i + 1] = bsum[i] + b[i];
  bsum.push_back(inf);
  for (int p = 0; p <= n; ++p) {
    ll target = k - asum[p];
    if (target < 0)
      break;
    int q = lower_bound(bsum.begin(), bsum.end(), target) - bsum.begin();
    if (bsum[q] > target)
      --q;
    ans = max(p + q, ans);
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define l_ength size
const int inf = (1 << 30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  vector<ll> b(m);
  for (auto &t : a)
    cin >> t;
  for (auto &t : b)
    cin >> t;
  vector<ll> asum(n + 1, 0);
  vector<ll> bsum(n + 1, 0);
  int ans = 0;
  for (int i = 0; i < n; ++i)
    asum[i + 1] = asum[i] + a[i];
  for (int i = 0; i < m; ++i)
    bsum[i + 1] = bsum[i] + b[i];
  for (int p = 0; p <= n; ++p) {
    ll target = k - asum[p];
    if (target < 0)
      continue;
    int q = lower_bound(bsum.begin(), bsum.end(), target) - bsum.begin();
    if (bsum[q] > target)
      --q;
    ans = max(p + q, ans);
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  long long N, M, K, X, count = 0;
  vector<long long> A, B, c;

  cin >> N >> M >> K;

  A.push_back(0);
  for (int i = 1; i <= N; i++) {
    cin >> X;
    A.push_back(X + A[i - 1]);
  }
  B.push_back(0);
  for (int i = 1; i <= M; i++) {
    cin >> X;
    B.push_back(X + B[i - 1]);
  }
  int ans = 0;
  for (int i = 0, j = 0; i <= N; i++) {
    if (K < A[i]) {
      break;
    }
    int left = 0, right = M, mid;
    while (left <= right) {
      mid = (left + right) / 2;
      if (A[i] + B[mid] <= K) {
        ans = max(i + mid, ans);
        left = mid + 1;
      } else {
        right = mid - 1;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

int main(void) {
  long long N, M, K, X, count = 0;
  vector<long long> A, B, c;

  cin >> N >> M >> K;

  A.push_back(0);
  for (int i = 1; i <= N; i++) {
    cin >> X;
    A.push_back(X + A[i - 1]);
  }
  B.push_back(0);
  for (int i = 1; i <= M; i++) {
    cin >> X;
    B.push_back(X + B[i - 1]);
  }
  int ans = 0;
  for (int i = 0, j = 0; i <= N; i++, j = 0) {
    if (K < A[i]) {
      break;
    }
    while (A[i] + B[j] <= K && j <= M) {
      j++;
    }
    j--;
    ans = max(i + j, ans);
  }
  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}
const int MOD = 1000000007;

void solve() {
  int 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];
  vector<ll> sumA(n + 1);
  vector<ll> sumB(m + 1);
  rep(i, n) sumA[i + 1] = sumA[i] + a[i];
  rep(i, m) sumB[i + 1] = sumB[i] + b[i];
  int ans = 0;
  rep(i, n + 1) {
    if (sumA[i] > k)
      continue;
    ll s = sumA[i];
    ll t = k - s;
    int j = upper_bound(sumB.begin(), sumB.end(), t) - sumB.begin();
    int temp = i + (j - 1);
    ans = max(temp, ans);
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}
const int MOD = 1000000007;

void solve() {
  int 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];
  vector<ll> sumA(n);
  vector<ll> sumB(m);
  sumA[0] = a[0];
  sumB[0] = b[0];
  rep(i, n - 1) sumA[i + 1] = sumA[i] + a[i + 1];
  rep(i, m - 1) sumB[i + 1] = sumB[i] + a[i + 1];
  int ans = 0;
  rep(i, n) {
    if (sumA[i] > k)
      continue;
    int s = k - sumA[i];

    int p = lower_bound(sumB.begin(), sumB.end(), s) - sumB.begin();

    int temp = i + 1 + p;
    ans = max(ans, temp);
  }

  cout << ans << endl;
}

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

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

int main() {
  int64_t n, m;
  int64_t k;
  cin >> n >> m >> k;
  vector<int64_t> a(n);
  vector<int64_t> b(m);
  vector<int64_t> as(n + 1, 0);
  vector<int64_t> bs(m + 1, 0);
  for (int64_t i = 0; i < n; i++) {
    cin >> a.at(i);
    as.at(i + 1) = as.at(i) + a.at(i);
  }
  for (int64_t i = 0; i < m; i++) {
    cin >> b.at(i);
    bs.at(i + 1) = bs.at(i) + b.at(i);
  }
  int64_t tmp = m;
  int64_t ans = 0;
  for (int64_t i = 0; i < n + 1; i++) {
    if (as.at(i) > k)
      break;
    for (int64_t j = tmp; j >= 0; j--) {
      if (as.at(i) + bs.at(j) <= k) {
        ans = max(ans, i + j);
        tmp = j;
        break;
      }
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int64_t n, m, k;
int64_t answer = 0;

void tun(vector<int64_t> &a, vector<int64_t> &b, int64_t k, int64_t ai,
         int64_t bi, int64_t ans) {
  if (ai >= n) {
    while (1) {
      k -= b.at(bi);
      if (k >= 0) {
        ans++;
        bi++;
        answer = max(answer, ans);
      } else {
        answer = max(answer, ans);
      }
      return;
    }
  }
  if (bi >= m) {
    while (1) {
      k -= a.at(ai);
      if (k >= 0) {
        ans++;
        ai++;
        answer = max(answer, ans);
      } else {
        answer = max(answer, ans);
      }
      return;
    }
  }
  if (k < a.at(ai) && k < b.at(bi)) {
    answer = max(answer, ans);
    return;
  }
  if (ai < n && a.at(ai) <= k) {
    tun(a, b, k - a.at(ai), ai + 1, bi, ans + 1);
  }
  if (bi < m && b.at(bi) <= k) {
    tun(a, b, k - b.at(bi), ai, bi + 1, ans + 1);
  }
}

int main() {
  cin >> n >> m >> k;
  vector<int64_t> a(n);
  vector<int64_t> b(m);
  for (int64_t i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int64_t i = 0; i < m; i++) {
    cin >> b.at(i);
  }
  tun(a, b, k, 0, 0, 0);
  cout << answer << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define speed                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#define FL(i, a, n) for (ll i = a; i < n; i++)
#define even(x) (((x) % (2)) == (0))
#define odd(x) (((x) % (2)) == (1))
#define meme(x) memset(x, 0, sizeof(x))
#define mod 1000000007

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

ll claw[2000003];
ll infant[2000003];

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

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

  cout << cnt;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define speed                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#define FL(i, a, n) for (ll i = a; i < n; i++)
#define even(x) (((x) % (2)) == (0))
#define odd(x) (((x) % (2)) == (1))
#define meme(x) memset(x, 0, sizeof(x))
#define mod 1000000007

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

ll claw[2000003];
ll infant[2000003];

int main() {
  ll n, m;
  cin >> n >> m;
  ll k;
  cin >> k;
  vector<ll> st, stt;
  for (ll i = 0; i < n; i++) {
    ll xx;
    cin >> xx;
    st.pb(xx);
  }
  for (ll i = 0; i < m; i++) {
    ll xx;
    cin >> xx;
    stt.pb(xx);
  }
  ll cnt = 0;
  ll i = 0, j = 0;
  while (k > 0 && i + j < m + n) {
    cnt++;
    // cout<<k<<endl;
    if (st[i] <= stt[j]) {
      k -= st[i];
      i++;
    } else {
      k -= stt[j];
      j++;
    }
  }
  if (k < 0)
    cout << cnt - 1;
  else
    cout << cnt;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\\n"
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  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];
  ll ans = 0;
  ll cur = 0;
  ll t = 0;
  while (cur < n && t + a[cur] <= k) {
    ans++;
    t += a[cur++];
  }
  ll Max = ans;
  if (cur)
    cur--;
  for (ll i = 0; i < m;) {
    if (t + b[i] <= k) {
      ans++;
      Max = max(Max, ans);
      t += b[i++];
      continue;
    } else {
      if (cur >= 0)
        t = max(0ll, t - a[cur--]);
      else
        break;
      ans--;
    }
  }
  cout << Max;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\\n"
ll dfs(ll i, ll j, vector<ll> &a, vector<ll> &b, ll k,
       map<pair<ll, ll>, ll> &dp) {
  if (i >= (ll)a.size() && j >= (ll)b.size())
    return 0;
  if (dp.count({i, j}))
    return dp[{i, j}];
  ll ans1 = 0, ans2 = 0;
  if (i < a.size() && k - a[i] >= 0)
    ans1 = 1 + dfs(i + 1, j, a, b, k - a[i], dp);
  if (j < b.size() && k - b[j] >= 0)
    ans2 = 1 + dfs(i, j + 1, a, b, k - b[j], dp);
  return dp[{i, j}] = max(ans1, ans2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  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];
  map<pair<ll, ll>, ll> dp;
  ll ans = dfs(0, 0, a, b, k, dp);
  cout << ans;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <list>
#include <vector>
#define endl "\\n"
#define eb emplace_back
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(n) for (int i = n - 1; i >= 0; --i)
#define FORE(n) for (const auto &i : n)
typedef long long ll;
using namespace std;

bool desc(int a, int b) { return a > b; }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, m, k;
  cin >> n >> m >> k;
  int arr_a[n + 1], arr_b[m + 1];
  vector<ll> a, b;
  a.emplace_back(0);
  b.emplace_back(0);
  FOR(i, 0, n) {
    cin >> arr_a[i];
    a.emplace_back(a[i] + arr_a[i]);
  }
  FOR(i, 0, m) {
    cin >> arr_b[i];
    b.emplace_back(b[i] + arr_b[i]);
  }
  /*
  FORE(a)
      cout << i << " ";
  cout << endl;
  FORE(b)
      cout << i << " ";
  */
  ll high = 0;
  ll i = 0;
  ll j = b.size() - 1;
  for (i = 0; i < n + 1; i++) {
    if (a[i] > k)
      break;
    // cout << a[i] << b[j] << endl;
    while (a[i] + b[j] > k) {
      // cout << b[j] << endl;
      --j;
    }
    high = max(i + j, high);
  }
  cout << high << endl;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
#include <list>
#include <vector>
#define endl "\\n"
#define eb emplace_back
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FORR(n) for (int i = n - 1; i >= 0; --i)
typedef long long ll;
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, m, k;
  cin >> n >> m >> k;
  int arr_a[n + 1], arr_b[m + 1];
  vector<int> a, b;
  a.emplace_back(0), b.emplace_back(0);
  FOR(i, n) {
    cin >> arr_a[i];
    a.emplace_back(a[i] + arr_a[i]);
  }
  FOR(i, m) {
    cin >> arr_b[i];
    b.emplace_back(b[i] + arr_b[i]);
  }
  ll high = -1;
  FOR(i, n + 1) {
    if (a[i] > k)
      break;
    ll current = 0;
    ll j = 0;
    while (a[i] + b[j] <= k) {
      current = i + j;
      high = max(current, high);
      j++;
    }
  }
  cout << high << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <functional>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <math.h>
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
  int N, M;
  cin >> N >> M;
  int32_t K;
  cin >> K;
  vector<ll> A(N + 1), B(M + 1);
  int tmp;
  cin >> tmp;
  A.at(1) = tmp;
  for (int i = 2; i <= N; i++) {
    cin >> tmp;
    A.at(i) = A.at(i - 1) + tmp;
  }
  cin >> tmp;
  B.at(1) = tmp;
  for (int i = 2; i <= M; i++) {
    cin >> tmp;
    B.at(i) = B.at(i - 1) + tmp;
  }
  int ans = 0, x = M;
  for (int i = 0; i <= N; i++) {
    if (A.at(i) > K)
      continue;
    while (A.at(i) + B.at(x) > K) {
      x--;
    }
    ans = max(ans, i + x);
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <functional>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <math.h>
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
  int N, M;
  cin >> N >> M;
  int32_t K;
  cin >> K;
  vector<ll> A(N + 1), B(M + 1);
  int tmp;
  cin >> tmp;
  A.at(1) = tmp;
  for (int i = 2; i <= N; i++) {
    cin >> tmp;
    A.at(i) = A.at(i - 1) + tmp;
  }
  cin >> tmp;
  B.at(1) = tmp;
  for (int i = 2; i <= M; i++) {
    cin >> tmp;
    B.at(i) = B.at(i - 1) + tmp;
  }
  int ans = 0;
  for (int i = N; i >= 0; i--) {
    if (A.at(i) > K)
      continue;
    for (int j = M; j >= 0; j--) {
      if (A.at(i) + B.at(j) > K)
        continue;
      ans = max(ans, i + j);
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
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);

  for (ll i = 0; i < N; i++) {
    ll x;
    cin >> x;
    a.at(i + 1) = a.at(i) + x;
  }

  /*
  for(int i=0;i<N+1;i++){
        cout << a.at(i) << endl;
  }
  */

  for (ll i = 0; i < M; i++) {
    ll x;
    cin >> x;
    b.at(i + 1) = b.at(i) + x;
  }

  ll ans = 0;
  ll j = M;
  for (ll i = 0; i < N + 1; i++) {
    if (a.at(i) > K) {
      break;
    }
    while (b.at(j) > K - a.at(i)) {
      j--;
    }
    if (ans < i + j) {
      ans = i + j;
    }
  }

  cout << ans << endl;

  return (0);
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

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

  vector<ll> asum(N + 1, 0);
  vector<ll> bsum(M + 1, 0);
  asum.at(0) = 0;
  bsum.at(0) = 0;

  for (int i = 0; i < N; i++) {
    asum.at(i + 1) = asum.at(i) + a.at(i);
  }

  /*
  for(int i=0;i<N+1;i++){
    cout << asum.at(i) << endl;
  }
  */

  for (int i = 0; i < M; i++) {
    bsum.at(i + 1) = bsum.at(i) + b.at(i);
  }

  ll best0;
  for (ll i = 0; i < N; i++) {
    if (asum.at(i) > K) {
      best0 = i - 1;
      break;
    }
  }

  ll ans = 0;
  for (int i = 0; i <= N; i++) {
    if (asum.at(i) > K) {
      break;
    }
    ll j = M;
    while (bsum.at(j) > K - asum.at(i)) {
      j--;
    }
    if (ans < i + j) {
      ans = i + j;
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
#define pb push_back
#define sc(n) scanf("%d", &n)
#define lsc(n) scanf("%lld", &n)
#define all(x) x.begin(), x.end()
#define rep(i, n) for (i = 0; i < n; i++)
#define rep1(i, n) for (i = 1; i <= n; i++)
#define rev(i, n) for (i = n - 1; i >= 0; i--)
#define rev1(i, n) for (i = n; i > 0; i--)
#define in insert
#define IT ::iterator
#define pr(n) printf("%d\\n", n)
#define lpr(n) printf("%lld\\n", n);

int main() {
  ll n, m, i, j, k;
  cin >> n >> m >> k;
  ll a[n], b[m];
  rep(i, n) { cin >> a[i]; }
  rep(i, m) { cin >> b[i]; }
  ll pa[n + 1], pb[m + 1];
  pa[0] = 0LL, pb[0] = 0LL;
  rep(i, n) { pa[i + 1] = pa[i] + a[i]; }
  rep(i, m) { pb[i + 1] = pb[i] + b[i]; }
  j = m;
  ll ans = 0LL;
  rep(i, n + 1) {
    if (pa[i] > k) {
      break;
    }
    while (pb[j] > k - pa[i]) {
      j--;
    }
    ans = max(ans, i + j);
    // cout << ans << endl;
  }
  cout << ans;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
#define pb push_back
#define sc(n) scanf("%d", &n)
#define lsc(n) scanf("%lld", &n)
#define all(x) x.begin(), x.end()
#define rep(i, n) for (i = 0; i < n; i++)
#define rep1(i, n) for (i = 1; i <= n; i++)
#define rev(i, n) for (i = n - 1; i >= 0; i--)
#define rev1(i, n) for (i = n; i > 0; i--)
#define in insert
#define IT ::iterator
#define pr(n) printf("%d\\n", n)
#define lpr(n) printf("%lld\\n", n);

int main() {
  int n, m, k, i, j;
  cin >> n >> m >> k;
  queue<int> a, b;
  rep(i, n) {
    int m;
    cin >> m;
    a.push(m);
  }
  rep(i, m) {
    int mm;
    cin >> mm;
    b.push(mm);
  }
  ll ans = 0LL;
  while (k > 0) {
    // cout << " k  " << k << endl;
    // cout << a.front() << " " << b.front() << endl;
    if (a.front() < b.front()) {
      if (k - a.front() >= 0) {
        k -= a.front();
        ans++;
        a.pop();
      } else {
        break;
      }
    } else {
      if (k - b.front() >= 0) {
        k -= b.front();
        ans++;
        b.pop();
      } else {
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define SIS std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define lowbit(x) (x & -x)
typedef long long ll;
using namespace std;
const int MAX = 0x7ffffff;
int t;

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define SIS std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define lowbit(x) (x & -x)
using namespace std;
const int MAX = 0x7ffffff;
int t;

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

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

int main() {
  int N, M, K;
  long long sum = 0;
  cin >> N >> M >> K;
  vector<int> A(N), B(M);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int j = 0; j < M; j++) {
    cin >> B.at(j);
    sum += B.at(j);
  }
  int ans = 0;
  int j = M;
  for (int i = 0; i < N + 1; i++) {
    while (j > 0 && sum > K) {
      j--;
      sum -= B.at(j);
    }
    if (sum > K) {
      break;
    }
    ans = max(ans, i + j);
    if (i == N) {
      break;
    }
    sum += A.at(i);
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int N, M, K;
  long long sum = 0;
  cin >> N >> M >> K;
  vector<int> A(N), B(M);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int j = 0; j < N; j++) {
    cin >> B.at(j);
    sum += B.at(j);
  }
  int ans = 0;
  int j = M;
  for (int i = 0; i < N + 1; i++) {
    while (j > 0 && sum > K) {
      j--;
      sum -= B.at(j);
    }
    if (sum > K) {
      break;
    }
    ans = max(ans, i + j);
    if (i == N) {
      break;
    }
    sum += A.at(i);
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

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

Error: -6
free(): invalid size


Fixed submission:

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

int main(void) {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  vector<ll> b(m);
  a[0] = 0;
  b[0] = 0;
  ll time = 0, abooks = 0;
  rep(i, n) {
    cin >> a[i];
    if (time + a[i] <= k) {
      time += a[i];
      abooks = i;
    }
  }
  ll ans = abooks;
  rep(i, m) {
    cin >> b[i];
    time += b[i];
    while (time > k && abooks > 0) {
      time -= a[abooks];
      abooks--;
    }
    if (time <= k) {
      ans = max(ans, i + abooks);
    }
  }
  cout << ans << endl;
}