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

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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n, m, k, x;
  set<pair<ll, ll>> seta;
  vector<pair<ll, ll>> v;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (!seta.size())
      seta.insert({x, i});
    else
      seta.insert({x + (*seta.rbegin()).first, i});
  }
  for (int i = 1; i <= m; i++) {
    cin >> x;
    if (!v.size())
      v.push_back({x, i});
    else
      v.push_back({x + v[v.size() - 1].first, i});
  }
  ll ans = -2e18;
  for (auto it : seta) {
    ll val = it.first;
    ll need = k - val;
    if (need < 0)
      continue;
    if (need == 0) {
      ans = max(ans, it.second);
      continue;
    }
    ans = max(ans, it.second);
    ll l = 0, r = m - 1, mid;
    while (l <= r) {
      mid = (l + r) / 2;
      if (v[mid].first + val == k) {
        ans = max(ans, it.second + v[mid].second);
        break;
      } else if (v[mid].first + val > k)
        r = mid - 1;
      else {
        l = mid + 1;
        ans = max(ans, it.second + v[mid].second);
      }
    }
  }
  ll l = 0, r = m - 1, mid;
  while (l <= r) {
    mid = (l + r) / 2;
    if (v[mid].first == k) {
      ans = max(ans, v[mid].second);
      break;
    } else if (v[mid].first > k)
      r = mid - 1;
    else {
      l = mid + 1;
      ans = max(ans, v[mid].second);
    }
  }
  if (ans == -2e18)
    cout << 0;
  else
    cout << ans;
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n, m, k;
  queue<ll> a, b;
  cin >> n >> m >> k;
  ll x;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    a.push(x);
  }
  for (int i = 1; i <= m; i++) {
    cin >> x;
    b.push(x);
  }
  ll sum = 0, cnt = 0;
  while (sum + min(a.front(), b.front()) <= k) {
    if (min(a.front(), b.front()) == a.front()) {
      sum += a.front();
      a.pop();
    } else {
      sum += b.front();
      b.pop();
    }
    cnt++;
    if (cnt == n + m)
      break;
  }
  cout << cnt;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  int n, m;
  int64_t k;
  cin >> n >> m >> k;
  vector<int64_t> a(n + 1), b(m + 1);
  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];
  }

  int64_t ans = 0;
  for (int64_t i = 0, j = m; i <= n; i++) {
    if (a[i] > k)
      break;

    while (a[i] + b[j] > k)
      j--;
    ans = max(ans, i + j);
  }
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  int n, m, k;
  cin >> n >> m >> k;
  queue<int> fq, sq;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    fq.push(x);
  }
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    sq.push(x);
  }
  int ans = 0;
  while (k > 0) {
    if (fq.front() <= sq.front()) {
      if (k - fq.front() >= 0) {
        ans++;
        k -= fq.front();
        fq.pop();
      } else {
        break;
      }
    } else {
      if (k - fq.front() >= 0) {
        ans++;
        k -= fq.front();
        sq.pop();
      } else {
        break;
      }
    }
  }
  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() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1), b(m + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i + 1];
    a[i + 1] += a[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> b[j + 1];
    b[j + 1] += b[j];
  }

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 + 1];
    a[i + 1] = a[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> b[j + 1];
    b[j + 1] = b[j];
  }

  ll ans = 0;
  for (ll i = 0, j = m - 1; i < j;) {
    if (a[i] > k)
      break;
    while (a[i] + a[j] > k)
      j--;
    ans = max(ans, i + j);
    i++, j--;
  }
  cout << ans << "\\n";
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5 + 5;
ll a[maxn], b[maxn];
ll suma[maxn], sumb[maxn];
int main() {
  ios::sync_with_stdio(false);
  ll n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i], suma[i] = suma[i - 1] + a[i];
  for (int i = 1; i <= m; i++)
    cin >> b[i], sumb[i] = sumb[i - 1] + b[i];
  if (suma[n] + sumb[m] <= k) {
    cout << n + m << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (suma[i] > k)
      break;
    // cout << sumb + 1 + m << endl;
    int down = lower_bound(sumb + 1, sumb + 1 + m, k - suma[i]) - sumb;
    if (sumb[down] != k - suma[i])
      down--;
    ans = max(ans, down + i);
    //  cout << i << " " << down << endl;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5 + 5;
ll a[maxn], b[maxn];
int main() {
  ios::sync_with_stdio(false);
  ll n, m, k;
  cin >> n >> m >> k;
  ll up = 1, down = 1, sum = 0;
  for (int i = 1; i <= n; i++)
    cin >> a[i], sum += a[i];
  for (int i = 1; i <= m; i++)
    cin >> b[i], sum += b[i];
  if (sum <= k) {
    cout << n + m << endl;
    return 0;
  }
  ll ans = 0;
  for (int i = 1; i <= n + m; i++) {
    if (k < min(a[up], b[down])) {
      break;
    }

    k -= min(a[up], b[down]);
    ans++;

    if (a[up] >= b[down])
      down++;
    else
      up++;
  }
  cout << ans << endl;
  return 0;
}

/*
3 4 240
120 90 120
80 150 80 150
*/
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, z = 0;
  ll a[200005] = {}, b[200005] = {}, k;
  cin >> n >> m >> k;
  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++)
    a[i] += a[i - 1];
  for (int i = 1; i <= m; i++)
    b[i] += b[i - 1];
  for (int i = 0; i <= n; i++) {
    if (a[i] <= k) {
      int l = 0, r = m + 1;
      while (l + 1 < r) {
        int x = (l + r) / 2;
        if (a[i] + b[x] <= k)
          l = x;
        else
          r = x;
      }
      z = max(z, i + l);
    }
  }
  cout << z;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m, k, c = 0;
  cin >> n >> m >> k;
  vector<ll> a, b;
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  for (ll i = 0; i < m; i++)
    cin >> b[i];
  while (k >= min(b.back(), a.back())) {
    k -= min(b.back(), a.back());
    if (a.back() < b.back()) {
      a.pop_back();
    } else
      b.pop_back();
    c++;
  }
  cout << c;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define endl "\\n"
#define ll long long
#define ld long double
#define ff first
#define ss second

const long long MOD7 = 1000000007;

using namespace std;

vector<ll> RSQ(const vector<ll> &v) {
  vector<ll> ans(v.size() + 1);

  ans[0] = 0;
  for (size_t i = 1; i <= v.size(); i++) {
    ans[i] = ans[i - 1] + v[i - 1];
  }

  // for(int i = 0; i <= v.size(); i++) {
  //     cout << ans[i] << (i == v.size()? endl : " ");
  // }

  return ans;
}

int main() {
  ios::sync_with_stdio(0);
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> da(n), db(m);

  for (auto &ent : da)
    cin >> ent;

  for (auto &ent : db)
    cin >> ent;

  vector<ll> sa = RSQ(da), sb = RSQ(db);

  ll ans = 0, i, j = m;
  for (i = 0; i <= n; i++) {

    if (sa[i] > k)
      break;

    while (j >= 0 and sb[j] > k - sa[i])
      j--;

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

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define endl "\\n"
#define ll long long
#define ld long double
#define ff first
#define ss second

const long long MOD7 = 1000000007;

using namespace std;

vector<ll> RSQ(const vector<ll> &v) {
  vector<ll> ans(v.size() + 1);

  ans[0] = 0;
  for (int i = 1; i <= v.size(); i++) {
    ans[i] = ans[i - 1] + v[i - 1];
  }

  // for(int i = 0; i <= v.size(); i++) {
  //     cout << ans[i] << (i == v.size()? endl : " ");
  // }

  return ans;
}

int main() {
  ios::sync_with_stdio(0);
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> da(n), db(m);

  for (auto &ent : da)
    cin >> ent;

  for (auto &ent : db)
    cin >> ent;

  vector<ll> sa = RSQ(da), sb = RSQ(db);

  ll ans = 0, i, j;
  for (i = 0; i <= n; i++) {

    if (sa[i] > k)
      break;

    j = 0;
    while (j <= m and sb[j] <= k - sa[i])
      j++;

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

  cout << ans << endl;

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

#include <iostream>
using namespace std;
typedef long long ll;
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  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 a[n + 1], b[m + 1];
  a[0] = 0;
  b[0] = 0;
  for (ll i = 1; i <= n; i++) {
    a[i] = a[i - 1] + A[i - 1];
  }
  for (ll i = 1; i <= m; i++) {
    b[i] = b[i - 1] + B[i - 1];
  }
  ll max = 0, j = m;
  for (ll i = 0; i <= n; i++) {
    if (a[i] > k)
      break;
    while (b[j] > k - a[i]) {
      j--;
    }
    if ((i + j) > max)
      max = (i + j);
  }
  cout << max;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
typedef long long ll;
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  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 a[n + 1], b[m + 1];
  a[0] = 0;
  b[0] = 0;
  for (ll i = 1; i <= n; i++) {
    a[i] = a[i - 1] + A[i - 1];
  }
  for (ll i = 1; i <= m; i++) {
    b[i] = b[i - 1] + B[i - 1];
  }
  ll max = 0;
  for (ll i = 0; i <= n; i++) {
    for (ll j = 0; j <= m; j++) {
      if (a[i] + b[j] > k) {
        break;
      } else if ((i + j) > max) {
        max = (i + j);
      }
    }
  }
  cout << max;
}
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++)
using ll = long long;
int main() {
  int n, m, c;
  c = 0;
  ll k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1);
  vector<ll> b(m + 1);
  rep(i, n) { cin >> a[i + 1]; }
  rep(i, m) { cin >> b[i + 1]; }
  vector<ll> A(n + 1);
  vector<ll> B(m + 1);
  rep(i, n) { A[i + 1] = A[i] + a[i + 1]; }
  rep(i, m) { B[i + 1] = B[i] + b[i + 1]; }
  int x = m + 1;
  rep(i, n + 1) {
    if (A[i] > k) {
      break;
    }
    rep(j, x) {
      if (B[x - 1] + A[i] <= k) {
        c = max(c, i + x - 1);
        break;
      } else if (A[i] + B[x - 1 - j] <= k) {
        c = max(c, i + x - j - 1);
        x = x - j;
        break;
      }
    }
  }
  cout << c << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
int main() {
  int n, m, c;
  c = 0;
  ll k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1);
  vector<ll> b(m + 1);
  rep(i, n) { cin >> a[i + 1]; }
  rep(i, m) { cin >> b[i + 1]; }
  vector<ll> A(n + 1);
  vector<ll> B(m + 1);
  rep(i, n) { A[i + 1] = A[i] + a[i + 1]; }
  rep(i, m) { B[i + 1] = B[i] + b[i + 1]; }
  int x = m + 1;
  rep(i, n + 1) {
    if (A[i] > k) {
      break;
    }
    rep(j, x) {
      if (A[i] + B[j] > k) {
        c = max(c, i + j - 1);
        x = j + 1;
        break;
      }
      if (j == m) {
        c = max(c, i + j);
      }
    }
  }
  cout << c << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i += 1)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define repv(arr) for (auto it = arr[i].begin(); it != arr[i].end(); it++)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define ssortA(arr) stable_sort(arr.begin(), arr.end())
#define search(arr, c) binary_search(arr.begin(), arr.end(), c)
#define pb push_back
#define ll long long
#define LCM(a, b) boost::math::lcm(a, b)
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\\n');

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  ll k;
  cin >> n >> m >> k;
  vl arr(n + 1), b(m + 1);
  rep(i, 1, n + 1) { cin >> arr[i]; }
  rep(i, 1, m + 1) { cin >> b[i]; }
  int max = 0;

  vl prea(n + 1, 0), preb(m + 1, 0);
  rep(i, 1, n + 1) { prea[i] += prea[i - 1] + arr[i]; }
  rep(i, 1, m + 1) { preb[i] += preb[i - 1] + b[i]; }
  int i = 0, j = n;
  while (1) {
    if (j < 0 || i > m) {
      break;
    } else {
      if (prea[j] + preb[i] <= k) {
        if (i + j > max)
          max = i + j;
        i++;
      } else {
        j--;
      }
    }
  }
  cout << max << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i += 1)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define repv(arr) for (auto it = arr[i].begin(); it != arr[i].end(); it++)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define ssortA(arr) stable_sort(arr.begin(), arr.end())
#define search(arr, c) binary_search(arr.begin(), arr.end(), c)
#define pb push_back
#define ll long long
#define LCM(a, b) boost::math::lcm(a, b)
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\\n');

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  ll k;
  cin >> n >> m >> k;
  vl arr(n + 1), b(m + 1);
  rep(i, 1, n + 1) { cin >> arr[i]; }
  rep(i, 1, m + 1) { cin >> b[i]; }
  int max = 0;

  vl prea(n + 1, 0), preb(m + 1, 0);
  rep(i, 1, n + 1) { prea[i] += prea[i - 1] + arr[i]; }
  rep(i, 1, n + 1) { preb[i] += b[i] + preb[i - 1]; }
  int i = 1, j = n;
  while (1) {
    if (j < 0 || i > m) {
      break;
    } else {
      if (prea[j] + preb[i] <= k) {
        if (i + j > max)
          max = i + j;
        i++;
      } else {
        j--;
      }
    }
  }
  cout << max << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

// A.cpp : このファイルには 'main'
// 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

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

int main() {
  long long n, m, k, x;
  vector<long long> a, b;

  cin >> n >> m >> k;

  for (int i = 0; i < n; i++) {
    cin >> x;
    a.emplace_back(x);
  }
  for (int i = 0; i < m; i++) {
    cin >> x;
    b.emplace_back(x);
  }
  //   a[n] = 10000000000;
  // b[m] = 10000000000;
  /* long long sum = 0;
   int akey = 0;
   int bkey = 0;
   int ans = 0;*/

  vector<long long> asum(n + 1), bsum(m + 1);
  vector<double> cospa(n + 1), cospab(m + 1);
  asum[0] = 0;
  bsum[0] = 0;
  cospa[0] = 10000000000;
  cospab[0] = 10000000000;
  double mincospa = 1000000;
  long long ans = 0;
  bool ac = true;
  int amax, bmax;

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

  int mmax = m;

  for (int i = 0; i <= n; i++) {
    if (asum[i] > k)
      break;
    for (int j = mmax; j >= 0; j--) {
      if (asum[i] + bsum[j] <= k) {
        mmax = j;
        if (i + j > ans)
          ans = i + j;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

// A.cpp : このファイルには 'main'
// 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

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

int main() {
  long long n, m, k, x;
  vector<long long> a, b;

  cin >> n >> m >> k;

  for (int i = 0; i < n; i++) {
    cin >> x;
    a.emplace_back(x);
  }
  for (int i = 0; i < m; i++) {
    cin >> x;
    b.emplace_back(x);
  }
  //   a[n] = 10000000000;
  // b[m] = 10000000000;
  /* long long sum = 0;
   int akey = 0;
   int bkey = 0;
   int ans = 0;*/

  vector<long long> asum(n + 1), bsum(m + 1);
  asum[0] = 0;
  bsum[0] = 0;

  long long ans = 0;

  for (int i = 1; i <= n; i++) {
    asum[i] = asum[i - 1] + a[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    bsum[i] = bsum[i - 1] + b[i - 1];
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (asum[i] + bsum[j] > k) {
        break;
      }
      if (i + j > ans) {
        ans = i + j;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

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

  vector<long long int> s1(n + 1), s2(m + 1);
  s1[0] = 0;
  s2[0] = 0;

  for (int i = 1; i <= n; i++) {

    cin >> s1[i];
    s1[i] = s1[i] + s1[i - 1];
  }

  for (int j = 1; j <= m; j++) {

    cin >> s2[j];
    s2[j] = s2[j] + s2[j - 1];
  }
  int max_book = 0;
  for (int i = 0; i <= n; i++) {
    if (k - s1[i] < 0)
      continue;
    int l = lower_bound(s2.begin(), s2.end(), k - s1[i]) - s2.begin();
    if (l > m || s2[l] > k - s1[i])
      l--;
    max_book = max(max_book, i + l);
  }
  cout << max_book << endl;

  return 0;
}

Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long int lli;
#define mxint 1000000007
const int mod = int(1e9 + 7);
long long int t[2000001];
/*
    int gcdExtended(int a, int b, int *x, int *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0;
        *y = 1;
        return b;
    }

    int x1, y1; // To store results of recursive call
    int gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}


*/

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

  vector<long long int> s1(n), s2(m);
  s1[0] = 0;
  s2[0] = 0;

  for (long long int i = 1; i <= n; i++) {

    cin >> s1[i];
    s1[i] = s1[i] + s1[i - 1];
  }

  for (long long int j = 1; j <= m; j++) {

    cin >> s2[j];
    s2[j] = s2[j] + s2[j - 1];
  }
  long long int max_book = 0;
  for (int i = 0; i <= n; i++) {
    if (k - s1[i] < 0)
      continue;
    long long int l = lower_bound(s2.begin(), s2.end(), k - s1[i]) - s2.begin();
    if (l > m || s2[l] > k - s1[i])
      l--;
    max_book = max(max_book, i + l);
  }
  cout << max_book << endl;

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

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1001001001;

ll max(ll a, ll b) { return (a < b) ? b : a; }

int main() {

  int n, m;
  ll k;
  cin >> n >> m >> k;
  ll a[n];
  ll b[m];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < m; i++)
    cin >> b[i];

  ll c[m + 1];
  c[0] = 0;
  for (int i = 0; i < m; i++) {
    c[i + 1] = c[i] + b[i];
  }

  ll ans = 0;
  ll t = 0;
  for (int i = 0; i <= n; i++) {
    if (i != 0) {
      t += a[i - 1];
    }
    if (t > k)
      break;
    int left = -1;
    int right = m + 1;

    while (right - left > 1) {
      int mid = (right + left) / 2;
      if (c[mid] + t <= k)
        left = mid;
      else
        right = mid;
    }
    ans = max(ans, i + left);
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
const int INF = 1001001001;

ll min(ll a, ll b) { return (a < b) ? a : b; }

ll max(ll a, ll b) { return (a < b) ? b : a; }

int main() {

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

  ll a[n];
  ll b[n];

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

  ll idx_a = 0;
  ll idx_b = 0;
  ll ans = 0;
  while (k > 0) {
    ll tmp = min(a[idx_a], b[idx_b]);
    k -= tmp;
    if (k < 0)
      break;
    if (a[idx_a] < b[idx_b]) {
      idx_a++;
    } else {
      idx_b++;
    }
    ans++;
  }

  cout << ans << endl;

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

#include <iostream>
using namespace std;

typedef long long ll;

ll a[200005], b[200005];
ll min1;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  ll sum1 = 0, sum2 = 0;
  for (ll i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (ll i = 1; i <= n; i++) {
    if (sum1 + a[i] <= k) {
      sum1 += a[i];
      sum2 = i;
    } else {
      break;
    }
  }
  for (ll i = 1; i <= m; i++) {
    cin >> b[i];
  }
  if (sum2 == 0) {
    ll sum123 = 0, sum246 = 0;
    for (ll i = 1; i <= m; i++) {
      if (sum123 + b[i] <= k) {
        sum123 + b[i];
        sum246 = i;
      } else {
        break;
      }
    }
    cout << sum246 << endl;
    return 0;
  }
  ll sum3 = sum1, sum4 = sum2;
  ll max1 = sum2;
  ll rem = 1;
  while (sum2 >= 1 && rem <= m) {
    while (sum2 >= 1 && sum3 + b[rem] > k) {
      sum3 -= a[sum2--];
      sum4--;
    }
    while (rem <= m && sum3 + b[rem] <= k) {
      sum3 += b[rem++];
      sum4++;
    }
    max1 = max(max1, sum4);
    //		cout<<sum2<<" "<<rem<<" "<<max1<<" "<<sum3<<endl;
  }
  cout << max1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

typedef long long ll;

ll n, m, k;
ll a[200005], b[200005];
ll min1, cntt1, cntt2;
void dfs(ll sum1, ll sum2, ll cnt1, ll cnt2) {
  min1 = max(min1, sum2);
  if (cntt1 < cnt1 - 1 && cntt2 < cnt2 - 1) {
    cntt1 = cnt1 - 1;
    cntt2 = cnt2 - 1;
  }
  if (cntt1 >= cnt1 && cntt2 >= cnt2) {
    return;
  }
  if (cnt1 <= n && sum1 + a[cnt1] <= k) {
    dfs(sum1 + a[cnt1], sum2 + 1, cnt1 + 1, cnt2);
  }
  if (cnt2 <= m && sum1 + b[cnt2] <= k) {
    dfs(sum1 + b[cnt2], sum2 + 1, cnt1, cnt2 + 1);
  }
  return;
}

int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> k;
  for (ll i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (ll i = 1; i <= m; i++) {
    cin >> b[i];
  }
  min1 = 0, cntt1 = 0, cntt2 = 0;
  dfs(0, 0, 1, 1);
  cout << min1 << endl;
  return 0;
}