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

#include <bits/stdc++.h>

using namespace std;

bool is_digit(char c) { return c >= '0' && c <= '9'; }

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n), b(m);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  vector<long long> sa(n + 1), sb(m + 1);
  sa[0] = 0;
  for (int i = 0; i < n; i++) {
    sa[i + 1] = a[i] + sa[i];
  }
  sb[0] = 0;
  for (int i = 0; i < m; i++) {
    sb[i + 1] = b[i] + sb[i];
  }
  int res = 0;
  for (int i = 0; i <= n; i++) {
    if (sa[i] > k)
      break;
    int l = 0, r = m + 1;
    while (r - l > 1) {
      int mid = (r + l) / 2;
      if (sa[i] + sb[mid] > k) {
        r = mid;
      } else {
        l = mid;
      }
    }
    res = max(res, i + l);
  }
  cout << res;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

bool is_digit(char c) { return c >= '0' && c <= '9'; }

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n), b(m);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  vector<long long> sa(n + 1), sb(m + 1);
  sa[0] = 0;
  for (int i = 0; i < n; i++) {
    sa[i + 1] = a[i] + sa[i];
  }
  sb[0] = 0;
  for (int i = 0; i < m; i++) {
    sb[i + 1] = a[i] + sb[i];
  }
  int res = 0;
  for (int i = 0; i <= n; i++) {
    if (sa[i] > k)
      break;
    int l = 0, r = m + 1;
    while (r - l > 1) {
      int mid = (r + l) / 2;
      if (sa[i] + sb[mid] > k) {
        r = mid;
      } else {
        l = mid;
      }
    }
    res = max(res, i + l);
  }
  cout << res;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M;
  long long K;
  cin >> N >> M >> K;
  vector<long long> A(N), B(M);
  for (auto &i : A)
    cin >> i;
  for (auto &i : B)
    cin >> i;

  vector<long long> Asum(N + 1, 0), Bsum(M + 1, 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];

  int ans = 0;
  for (int i = 0; i <= N && Asum[i] <= K; i++) {
    int tmp = i;
    auto it = upper_bound(Bsum.begin(), Bsum.end(), K - Asum[i]);
    tmp += (it - Bsum.begin()) - 1;
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int N, M;
  long long K;
  cin >> N >> M >> K;
  vector<long long> A(N), B(M);
  for (auto &i : A)
    cin >> i;
  for (auto &i : B)
    cin >> i;

  vector<long long> Asum(N), Bsum(M);
  Asum[0] = A[0];
  Bsum[0] = B[0];
  for (int i = 0; i < N - 1; i++)
    Asum[i + 1] = Asum[i] + A[i + 1];
  for (int i = 0; i < M - 1; i++)
    Bsum[i + 1] = Bsum[i] + B[i + 1];

  int ans = 0;
  for (int i = 0; Asum[i] <= K; i++) {
    int tmp = i + 1;
    auto it = upper_bound(Bsum.begin(), Bsum.end(), K - Asum[i]);
    tmp += (it - Bsum.begin());
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vc = vector<char>;
using vvll = vector<vll>;
using vvi = vector<vi>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using vpii = vector<pii>;

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vll A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  vll B(M);
  for (int i = 0; i < M; i++)
    cin >> B.at(i);

  vll A_time(N + 1), B_time(M + 1);
  int max_i = 0, tmp_j = M;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    A_time.at(i + 1) = A_time.at(i) + A.at(i);
    if (A_time.at(i + 1) < K)
      max_i = i + 1;
  }
  for (int j = 0; j < M; j++) {
    B_time.at(j + 1) = B_time.at(j) + B.at(j);
  }
  for (int i = 0; i <= N; i++) {
    if (A_time.at(i) > K)
      break;
    while (B_time.at(tmp_j) > K - A_time.at(i)) {
      tmp_j--;
    }
    ans = max(ans, i + tmp_j);
  }

  cout << ans << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vc = vector<char>;
using vvll = vector<vll>;
using vvi = vector<vi>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using vpii = vector<pii>;

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vll A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  vll B(M);
  for (int i = 0; i < M; i++)
    cin >> B.at(i);

  vll A_time(N + 1), B_time(M + 1);
  int max_i = 0, tmp_j = 0;
  int ans = 0;
  for (int i = 0; i <= N; i++) {
    A_time.at(i + 1) = A_time.at(i) + A.at(i);
    if (A_time.at(i + 1) < K)
      max_i = i + 1;
  }
  for (int j = 0; j <= M; j++) {
    B_time.at(j + 1) = B_time.at(j) + B.at(j);
  }

  for (int i = max_i; i >= 0; i--) {
    for (int j = tmp_j; j <= M; j++) {
      if (A_time.at(i) + B_time.at(j) > K) {
        tmp_j = j - 1;
        break;
      } else if (j == M) {
        tmp_j = M;
      }
    }

    if (i + tmp_j > ans)
      ans = i + tmp_j;
  }

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

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

typedef long long ll;

// int n, k, t;
// vector<int> v(2e5 + 100);
// vector<int> a(2e5 + 100);
// vectior<vector<int>> dp(2e5 + 100, -1);
// map<pair<int,int>,int> m;
// int rec(int indexv,int indexa,  int tt, int cnt) {
// 9if (index[
// if (m[{indexv,indexa}]) {
// return m[{indexv,indexa}];
//}
// if (tt == t) {
// return m[{indexv,indexa}] = cnt;
//}
// if (tt > t) {
// return m[{indexv,indexa}] = cnt - 1;
//}
// if (indexv >= n && indexa >= k) {
// return m[{indexv,indexa}] = 0;
//}
// int p = 0;
// if (indexv >= n) {
// p += rec(indexv,indexa + 1,tt + a[indexa], cnt + 1);
//}
// else if (indexa  >= k) {
// p += rec(indexv + 1,indexa,tt + v[indexv], cnt + 1);
//}else {
// p += max(rec(indexv + 1,indexa,tt + v[indexv], cnt + 1),rec(indexv,indexa +
// 1,tt + a[indexa], cnt + 1));
//}
// return m[{indexv,indexa}] = p;
// return dp[
//}

int main() {
  ll n, k, t;
  cin >> n >> k >> t;
  vector<ll> v(n + 1);
  vector<ll> a(k + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> v[i];
    v[i] = v[i] + v[i - 1];
  }
  for (int i = 1; i <= k; ++i) {
    cin >> a[i];
    a[i] = a[i] + a[i - 1];
  }
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    if (t - v[i] < 0) {
      continue;
    }
    // cout << "222" << " ";
    auto it = lower_bound(a.begin(), a.end(), t - v[i]);
    if (it != a.end()) {
      //--it;
      int p = it - a.begin();
      // cout <<  p << endl;
      if (t - v[i] == *it) {
        ans = max(ans, i + p);
      } else {
        ans = max(ans, i + p - 1);
      }
    }
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

typedef long long ll;

int n, k, t;
vector<int> v(2e5 + 100);
vector<int> a(2e5 + 100);
// vectior<vector<int>> dp(2e5 + 100, -1);
map<pair<int, int>, int> m;
int rec(int indexv, int indexa, int tt, int cnt) {
  // 9if (index[
  if (m[{indexv, indexa}]) {
    return m[{indexv, indexa}];
  }
  if (tt == t) {
    return m[{indexv, indexa}] = cnt;
  }
  if (tt > t) {
    return m[{indexv, indexa}] = cnt - 1;
  }
  if (indexv >= n && indexa >= k) {
    return m[{indexv, indexa}] = 0;
  }
  int p = 0;
  if (indexv >= n) {
    p += rec(indexv, indexa + 1, tt + a[indexa], cnt + 1);
  } else if (indexa >= k) {
    p += rec(indexv + 1, indexa, tt + v[indexv], cnt + 1);
  } else {
    p += max(rec(indexv + 1, indexa, tt + v[indexv], cnt + 1),
             rec(indexv, indexa + 1, tt + a[indexa], cnt + 1));
  }
  return m[{indexv, indexa}] = p;
  // return dp[
}

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

  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  for (int i = 0; i < k; ++i) {
    cin >> a[i];
  }
  cout << rec(0, 0, 0, 0);
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define all(v) (v).begin(), (v).end()
#define pii pair<ll, ll>
#define vii vector<pii>
#define MOD 1000000007LL
#define calc_fact(n) tgamma(n + 1)

signed main() {
  FIO;
  ll n, m, k, a, ans = LONG_LONG_MIN, sum = 0, j = 0;
  cin >> n >> m >> k;
  vi v1, v2;
  for (ll i = 0; i < n; i++) {
    cin >> a;
    v1.pb(a);
  }
  for (ll i = 0; i < m; i++) {
    cin >> a;
    v2.pb(a);
  }
  while (j < n and sum + v1[j] <= k)
    sum += v1[j++];
  ll p = 0;
  while (p < m and sum + v2[p] <= k)
    sum += v2[p++];
  ans = max(ans, j + p);
  j--;
  while (j >= 0) {
    sum -= v1[j--];
    while (p < m and sum + v2[p] <= k)
      sum += v2[p++];
    ans = max(ans, p + j + 1);
  }
  cout << ans;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define all(v) (v).begin(), (v).end()
#define pii pair<ll, ll>
#define vii vector<pii>
#define MOD 1000000007LL
#define calc_fact(n) tgamma(n + 1)

signed main() {
  FIO;
  ll n, m, k, a, ans = LONG_LONG_MIN, sum = 0, j = 0;
  cin >> n >> m >> k;
  vi v1, v2;
  for (ll i = 0; i < n; i++) {
    cin >> a;
    v1.pb(a);
  }
  for (ll i = 0; i < m; i++) {
    cin >> a;
    v2.pb(a);
  }
  while (j <= n and sum <= k) {
    ll t = 0, s = k - sum;
    while (t < m and s - v2[t] >= 0) {
      s -= v2[t++];
    }
    ans = max(ans, t + j);
    sum += v1[j++];
  }
  cout << ans;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

const int sz = 1e5 + 1;
ll mod = 1e9 + 7;

bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.first == b.first) {
    return a.second < b.second;
  } else {
    return a.first > b.first;
  }
}

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

  int t;
  t = 1;
  // cin>>t;
  // sieve();
  for (int cs = 1; cs <= t; cs++) {

    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> sum1(n + 1, 0), sum2(m + 1, 0);
    for (int i = 1; i <= n; i++) {
      ll x;
      cin >> x;
      sum1[i] = sum1[i - 1] + x;
    }
    for (int i = 1; i <= m; i++) {
      ll x;
      cin >> x;
      sum2[i] = sum2[i - 1] + x;
    }
    ll res = 0;
    for (int i = 0; i <= n; i++) {
      ll left = k - sum1[i];
      if (left < 0)
        break;
      ll pos = lower_bound(sum2.begin(), sum2.end(), left) - sum2.begin();
      if (pos > m or sum2[pos] > left)
        pos--;
      res = max(res, i + pos);
    }

    cout << res << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

const int sz = 1e5 + 1;
ll mod = 1e9 + 7;

bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.first == b.first) {
    return a.second < b.second;
  } else {
    return a.first > b.first;
  }
}

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

  int t;
  t = 1;
  // cin>>t;
  // sieve();
  for (int cs = 1; cs <= t; cs++) {

    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> sum1(n + 1, 0), sum2(n + 1, 0);
    for (int i = 1; i <= n; i++) {
      ll x;
      cin >> x;
      sum1[i] = sum1[i - 1] + x;
    }
    for (int i = 1; i <= m; i++) {
      ll x;
      cin >> x;
      sum2[i] = sum2[i - 1] + x;
    }
    ll res = 0;
    for (int i = 0; i <= n; i++) {
      ll left = k - sum1[i];
      if (left <= 0)
        break;
      ll pos = lower_bound(sum2.begin(), sum2.end(), left) - sum2.begin();
      if (pos > m or sum2[pos] > left)
        pos--;
      res = max(res, i + pos);
    }

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

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>

using namespace std;
const int maxn = 105;
const int inf = 0x3f3f3f3f;
typedef long long ll;

int main() {
#ifdef AZUKI_LOCAL
  freopen("../input.txt", "r", stdin);
  // freopen("../output.txt", "w", stdout);
#endif
  int n, m;
  ll k;
  while (cin >> n >> m >> k) {
    vector<ll> a(n), b(m), sum_a, sum_b;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    for (int i = 0; i < m; ++i) {
      cin >> b[i];
    }
    int ans = 0;
    sum_a.push_back(0);
    sum_b.push_back(0);
    for (int i = 0; i < n; ++i) {
      if (sum_a[i] > k)
        break;
      sum_a.push_back(sum_a[i] + a[i]);
    }
    for (int i = 0; i < m; ++i) {
      if (sum_b[i] > k)
        break;
      sum_b.push_back(sum_b[i] + b[i]);
    }
    int j = (int)sum_b.size() - 1;
    for (int i = 0; i < sum_a.size(); ++i) {
      if (sum_a[i] > k)
        break;
      while (sum_b[j] + sum_a[i] > k) {
        --j;
      }
      ans = max(ans, i + j);
    }
    cout << ans << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(e, i) for (auto e : i)
#define all(x) x.begin(), x.end()

using namespace std;
const int maxn = 105;
const int inf = 0x3f3f3f3f;
typedef long long ll;

int main() {
#ifdef AZUKI_LOCAL
  freopen("../input.txt", "r", stdin);
  // freopen("../output.txt", "w", stdout);
#endif
  int n, m, k;
  while (cin >> n >> m >> k) {
    vector<int> a(n), b(m), sum_a, sum_b;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    for (int i = 0; i < m; ++i) {
      cin >> b[i];
    }
    int ans = 0;
    sum_a.push_back(0);
    sum_b.push_back(0);
    for (int i = 0; i < n; ++i) {
      if (sum_a[i] > k)
        break;
      sum_a.push_back(sum_a[i] + a[i]);
    }
    for (int i = 0; i < m; ++i) {
      if (sum_b[i] > k)
        break;
      sum_b.push_back(sum_b[i] + b[i]);
    }
    int j = (int)sum_b.size() - 1;
    int sum_a_size = (int)sum_a.size();
    for (int i = 0; i < sum_a_size; ++i) {
      while (sum_b[j] + sum_a[i] > k) {
        --j;
      }
      ans = max(ans, i + j);
    }
    cout << ans << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <iomanip> //setprecision()
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using ll = long long;
using namespace std;

double Mcos(double k) { return cos(k * atan(1.0) * 4 / 180); }

void monmo() {}

int main() {
  int n, m, k;
  int a, b;
  int asum = 0, bsum = 0;
  int sum = 0, count = 0;
  cin >> n >> m >> k;
  vector<int> va(n), vb(m), v;
  for (int i = 0; i < n; i++) {
    cin >> va[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> vb[i];
  }

  for (a = 0; a < n; a++) {
    asum += va[a];
    if (asum > k) {
      asum -= va[a];
      break;
    }
  }

  for (b = 0; b < m; b++) {
    bsum += vb[b];
    if (bsum > k) {
      bsum -= vb[b];
      break;
    }
  }

  for (int i = a - 1; i >= 0; i--) {
    v.push_back(va[i]);
  }
  for (int i = 0; i < b; i++) {
    v.push_back(vb[i]);
  }

  int fast = 0;

  for (int i = 0; i < v.size(); i++) {
    sum += v[i];
    count++;
    if (sum > k) {
      sum -= v[fast];
      count--;
      fast++;
    }
  }
  cout << count;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip> //setprecision()
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using ll = long long;
using namespace std;
ll n, m, k;
ll cmax = 0;

double Mcos(double k) { return cos(k * atan(1.0) * 4 / 180); }

void monmo(vector<int> va, vector<int> vb, int a, int b, int count, int ksum) {
  while (true) {
    if (ksum > k)
      break;
    if (n == a && m == b) {
      count++;
      if (cmax < count)
        cmax = count;
      break;
    }
    if (n == a) {
      ksum += vb[b];
      b++;
      count++;
    } else if (m == b) {
      ksum += va[a];
      a++;
      count++;
    } else if (va[a] < vb[b]) {
      ksum += va[a];
      a++;
      count++;
    } else if (va[a] > vb[b]) {
      ksum += vb[b];
      b++;
      count++;
    } else if (va[a] == vb[b]) {
      monmo(va, vb, a + 1, b, count + 1, ksum + va[a]);
      monmo(va, vb, a, b + 1, count + 1, ksum + va[b]);
      break;
    }
    if (cmax < count)
      cmax = count;
  }
}

int main() {
  int a = 0, b = 0, count = 0, ksum = 0;
  cin >> n >> m >> k;
  vector<int> va(n), vb(m);
  for (int i = 0; i < n; i++) {
    cin >> va[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> vb[i];
  }

  monmo(va, vb, a, b, count, ksum);
  if (cmax == 0)
    cmax++;
  cout << cmax - 1;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) (x.begin()), (x.end())
#define allr(x) (x.rbegin()), (x.rend())
#define sz(x) ((ll)x.size())
#define FAST_IO                                                                \\
  ios_base ::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
using namespace std;
#ifdef LOCAL
#include "uj.h"
#endif

void tokenize(string str, const char delim, vector<string> &res) {
  stringstream p(str);
  string token;
  while (getline(p, token, delim)) {
    res.push_back(token);
  }
  return;
}

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

  int maxi = 0;
  for (int i = 0; i <= n && a[i] <= k; ++i) {
    int pos = 0;
    int lo = 0, hi = m;
    while (lo <= hi) {
      int mid = lo + (hi - lo) / 2;
      if (b[mid] + a[i] <= (ll)k)
        pos = mid, lo = mid + 1;
      else
        hi = mid - 1;
    }
    maxi = max(maxi, i + pos);
  }
  cout << maxi << endl;
  return;
}

int main() {
  FAST_IO;
  int tt;
  tt = 1;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "wt", stdout);
#endif
  //    cin >> tt;
  for (int i = 0; i < tt; ++i)
    test_case();
#ifndef ONLINE_JUDGE
  cerr << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\\n";
#endif

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) (x.begin()), (x.end())
#define sz(x) ((ll)x.size())
#define FAST_IO                                                                \\
  ios_base ::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
using namespace std;
#ifdef LOCAL
#include "uj.h"
#endif
void tokenize(string str, const char delim, vector<string> &res) {
  stringstream p(str);
  string token;
  while (getline(p, token, delim)) {
    res.push_back(token);
  }
  return;
}

// Your workSpace ...

ll N, M, k;

void test_case() {
  cin >> N >> M >> k;
  ll cnt = 0;

  vector<int> a(N), b(M);
  for (int i = 0; i < N; ++i)
    cin >> a[i];
  for (auto &el : b)
    cin >> el;

  ll tot = 0;
  int i = 0, j = 0;
  while (i < sz(a) && j < sz(b)) {
    if (a[i] < b[j]) {
      if (tot + a[i] > k)
        break;
      tot += a[i++];
      ++cnt;
    } else {
      if (tot + b[j] > k)
        break;
      tot += b[j++];
      ++cnt;
    }
  }
  while (i < sz(a) && tot + a[i] < k)
    ++cnt, tot += a[i++];

  while (j < sz(b) && tot + b[j] < k)
    ++cnt, tot += a[j++];

  cout << cnt;
}

int main() {
  FAST_IO;
  int tt;
  // cin>>tt;
  tt = 1;
  while (tt--) {
    test_case();
  }
#ifndef ONLINE_JUDGE
  cerr << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\\n";
#endif
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

ll solve(vector<ll> b_sum, ll x) {
  ll ok = -1;
  ll ng = b_sum.size();
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;

    if (x >= b_sum[mid])
      ok = mid;
    else
      ng = mid;
  }
  return ok;
}

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1), b(m + 1), b_sum(m + 1, 0);
  a[0] = 0;
  rep(i, n) cin >> a[i + 1];
  rep(i, m) {
    cin >> b[i];
    b_sum[i + 1] = b_sum[i] + b[i];
  }
  ll sum = 0, ans = 0;
  // rep(i, m + 1) cout << b_sum[i] << " ";
  // cout << endl;

  rep(i, n + 1) {
    sum += a[i];
    if (sum > k)
      break;
    // cout << "x = " << k - sum << endl;
    auto itr = upper_bound(b_sum.begin(), b_sum.end(), k - sum);
    // cout << "value = " << *itr << endl;
    ll num = itr - b_sum.begin() - 1;
    // ll num = solve(b_sum, k - sum);
    // cout << "i = " << i + 1 << " num = " << num << endl;
    ans = max(ans, num + i);
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

ll solve(vector<ll> b_sum, ll x) {
  ll ok = -1;
  ll ng = b_sum.size();
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;

    if (x >= b_sum[mid])
      ok = mid;
    else
      ng = mid;
  }
  return ok;
}

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1), b(m + 1), b_sum(m + 1, 0);
  rep(i, n) cin >> a[i];
  ll current = 0;
  rep(i, m) {
    cin >> b[i];
    b_sum[i + 1] = b_sum[i] + b[i];
  }
  a[n] = 1e+10;
  b[n] = 1e+10;
  ll sum = 0, ans = 0;

  rep(i, n) {
    sum += a[i];
    if (sum > k)
      continue;

    ll num = solve(b_sum, k - sum);
    ans = max(ans, i + 1 + num);
  }
  cout << ans << endl;
}