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

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;

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

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

  rep(i, N) { cin >> A[i]; }

  rep(i, M) { cin >> B[i]; }

  vector<ll> tA, tB;

  tA.push_back(0);
  tB.push_back(0);

  rep(i, N) { tA.push_back(tA[i] + A[i]); }
  rep(i, M) { tB.push_back(tB[i] + B[i]); }

  ll ans = 0, j = M;
  for (ll i = 0; i < N + 1; i++) {
    if (tA[i] > K) {
      break;
    } else {
      while (tB[j] > K - tA[i]) {
        j--;
      }
      ans = max(ans, i + j);
    }
  }

  cout << ans;

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
ll sum = 0, N, M, K, HN, HM;

void ans(ll i, ll j, vector<ll> A, vector<ll> B, ll T, ll count);

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

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

  rep(i, N) { cin >> A[i]; }

  rep(i, M) { cin >> B[i]; }

  ll tmp = 0;
  rep(i, N) {
    tmp += A[i];
    HN = i;
    if (tmp >= K) {
      break;
    }
  }

  tmp = 0;
  rep(i, M) {
    tmp += B[i];
    HN = i;
    if (tmp >= K) {
      break;
    }
  }

  ll i = 0, j = 0, T = K, count = 0;
  ans(i, j, A, B, T, count);

  cout << sum;

  return 0;
}

void ans(ll i, ll j, vector<ll> A, vector<ll> B, ll T, ll count) {
  ll T1 = T, T2 = T, count1 = count, count2 = count;
  if (i < HN) {
    T1 -= A[i];
    if (T1 >= 0) {
      count1++;
      sum = max(sum, count1);
      ans(i + 1, j, A, B, T1, count1);
    }
  }
  if (j < HM) {
    T2 -= B[j];
    if (T2 >= 0) {
      count2++;
      sum = max(sum, count2);
      ans(i, j + 1, A, B, T2, count2);
    }
  }
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize("Ofast")

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

using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m;
  int64_t k;
  cin >> n >> m >> k;
  vector<int64_t> a;
  vector<int64_t> b;
  a.emplace_back(0);
  b.emplace_back(0);
  int64_t tmp;
  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    a.emplace_back(tmp);
  }
  for (int i = 0, tmp; i < m; ++i) {
    cin >> tmp;
    b.emplace_back(tmp);
  }
  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];
  }

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

Error: 0

Fixed submission:

#pragma GCC optimize("Ofast")

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

using namespace std;
int main() {
  // ios::sync_with_stdio(false);
  // cin.tie(nullptr);

  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n + 1);
  vector<int> b(m + 1);
  vector<int> A(n);
  vector<int> B(m);
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> B[i];
  }
  a[0] = 0;
  b[0] = 0;
  int a_th = n + 1;
  for (int i = 1, tmp; i <= n; ++i) {
    tmp = A[i - 1] + a[i - 1];
    if (tmp > k) {
      a_th = i;
      break;
    }
    a[i] = tmp;
  }
  for (int i = 1; i <= m; ++i) {
    b[i] = B[i - 1] + b[i - 1];
  }

  int count = 0;
  for (int i = 0; i < a_th; ++i) {
    int j = 0;
    while (b[j] <= k - a[i]) {
      count = i + j;
      ++j;
    }
  }
  cout << count << "\\n";
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

#undef int
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
#define int long long int
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    int n, m, k;
    cin >> n >> m >> k;
    int crr[n], drr[m];
    for (int i = 0; i < n; i++) {
      cin >> crr[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> drr[i];
    }
    int s = 0;
    int i, j;
    for (i = 0; i < n; i++) {
      if (s + crr[i] <= k)
        s += crr[i];
      else
        break;
    }
    int z = i - 1;
    for (j = 0; j < m; j++) {
      if (s + drr[j] <= k)
        s += drr[j];
      else
        break;
    }
    int x = j;
    int ans = 0;
    ans = max(ans, z + x + 1);
    while (z >= 0) {
      if (x >= m)
        break;
      if (z < 0)
        break;
      s = s - crr[z];
      z--;
      ans = max(ans, z + x + 1);
      if (x >= m)
        break;
      while (s + drr[x] <= k) {
        if (x >= m)
          break;
        s += drr[x];
        x++;
        ans = max(ans, z + x + 1);
        if (x >= m)
          break;
      }
    }
    ans = max(ans, z + x + 1);
    cout << ans << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

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

#undef int
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
#define int long long int
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    int n, m, k;
    cin >> n >> m >> k;
    int crr[n], drr[n];
    for (int i = 0; i < n; i++) {
      cin >> crr[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> drr[i];
    }
    int s = 0;
    int i, j;
    for (i = 0; i < n; i++) {
      if (s + crr[i] <= k)
        s += crr[i];
      else
        break;
    }
    int z = i - 1;
    for (j = 0; j < m; j++) {
      if (s + drr[j] <= k)
        s += drr[j];
      else
        break;
    }
    int x = j;
    int ans = 0;
    ans = max(ans, z + x + 1);
    while (z >= 0) {
      if (x >= m)
        break;
      if (z < 0)
        break;
      s = s - crr[z];
      z--;
      ans = max(ans, z + x + 1);
      if (x >= m)
        break;
      while (s + drr[x] <= k) {
        if (x >= m)
          break;
        s += drr[x];
        x++;
        ans = max(ans, z + x + 1);
        if (x >= m)
          break;
      }
    }
    ans = max(ans, z + x + 1);
    cout << ans << endl;
  }
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main() {
  long long n, m, k, sum = 0, ans = 0;

  cin >> n >> m >> k;
  vector<long long> a(n + 1), b(m + 1);

  for (int i = 1; i <= n; i++) {
    long long s;
    cin >> s;
    a[i] = a[i - 1] + s;
  }

  for (int i = 1; i <= m; i++) {
    long long s;
    cin >> s;
    b[i] = b[i - 1] + s;
  }

  long long maxBooks = 0;
  for (int i = 0; i <= n; i++) {
    if (a[i] > k)
      break;
    long long bb = upper_bound(b.begin(), b.end(), k - a[i]) - b.begin();
    if (maxBooks < i + bb - 1)
      maxBooks = i + bb - 1;
  }

  cout << maxBooks << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main() {
  long long n, m, k, sum = 0, ans = 0;

  cin >> n >> m >> k;
  queue<long long> a, b;

  for (int i = 0; i < n; i++) {
    long s;
    cin >> s;
    a.push(s);
  }

  for (int i = 0; i < m; i++) {
    long s;
    cin >> s;
    b.push(s);
  }

  // cout << a.front() << " " << b.front() << endl;

  for (int i = 0; i < n + m; i++) {
    if (a.front() > k && b.front() > k)
      break;

    if (a.front() < b.front()) {
      sum += a.front();
      if (sum > k)
        break;
      a.pop();
      if (a.empty()) {
        a.push(2147483647);
      }
      ans++;
    } else {
      sum += b.front();
      if (sum > k)
        break;
      b.pop();
      ans++;
    }
  }

  cout << ans << 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 mp make_pair

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

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

  ll m = 0, mm = 0;
  ll s = 0;
  int i, j;
  for (i = 0; i < n; i++) {
    if (s + a[i] > k)
      break;
    s += a[i];
    m++;
  }
  for (j = 0; j < l; j++) {
    if (s + b[j] > k)
      break;
    s += b[j];
    m++;
  }
  mm = m;

  for (i--; i >= 0; i--) {
    s -= a[i];
    m--;
    while (j < l && s + b[j] <= k) {
      s += b[j];
      m++;
      j++;
    }
    mm = max(m, mm);
    if (j == l)
      break;
  }

  cout << mm;

  return 0;
}

Error: -11

Fixed submission:

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

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

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

  int m = 0, mm;
  ll s = 0;
  int i, j;
  for (i = 0; i < n; i++) {
    if (s + a[i] > k)
      break;
    s += a[i];
    m++;
  }
  for (j = 0; j < l; j++) {
    if (s + b[j] > k)
      break;
    s += b[j];
    m++;
  }
  mm = m;

  for (; j >= 0; j--) {
    s -= a[j];
    m--;
    while (i < l && s + b[i] <= k) {
      s += b[i];
      m++;
      i++;
    }
    mm = max(m, mm);
    if (i == l)
      break;
  }

  cout << mm;

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

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<long long> a(n + 1);
  vector<long long> b(m + 1);
  FOR(i, n) {
    int x;
    cin >> x;
    a[i + 1] = a[i] + x;
  }
  FOR(i, m) {
    int x;
    cin >> x;
    b[i + 1] = b[i] + x;
  }
  long long ans = 0;
  int temp = m;
  for (long long i = 0; i <= n; i++) {
    for (long long j = temp; j >= 0; j--) {
      if (a[i] + b[j] <= k) {
        ans = max(ans, i + j);
        temp = j;
        break;
      }
    }
  }
  cout << ans << endl;
}


Error: WA

Fixed submission:

// MISHON69
// DATE:6/24/2020
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  list<int> a;
  list<int> b;
  FOR(i, n) {
    int temp;
    cin >> temp;
    a.push_back(temp);
  }
  FOR(i, m) {
    int temp;
    cin >> temp;
    b.push_back(temp);
  }
  if (k < a.front() && k < b.front()) {
    cout << "0" << endl;
    return 0;
  }
  if (accumulate(a.begin(), a.end(), 0) + accumulate(b.begin(), b.end(), 0) <=
      k) {
    cout << n + m << endl;
    return 0;
  }
  vector<int> time;
  while (accumulate(time.begin(), time.end(), 0) <= k) {
    if (a.front() < b.front()) {
      time.push_back(a.front());
      a.pop_front();
    }
    if (b.front() <= a.front()) {
      time.push_back(b.front());
      b.pop_front();
    }
    if (b.empty() && !a.empty()) {
      time.push_back(a.front());
      a.pop_front();
    }
    if (a.empty() && !b.empty()) {
      time.push_back(b.front());
      b.pop_front();
    }
  }
  cout << time.size() - 1 << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

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

  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (a[i] > k)
      break;
    int l = 0, r = m + 1;
    while (r - l > 1) {
      int mid = (l + r) / 2;
      if (a[i] + b[mid] <= k)
        l = mid;
      else
        r = mid;
    }
    ans = max(ans, i + l);
  }
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

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

  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (a[i] > k)
      break;
    int l = 0, r = m + 1;
    while (r - l > 1) {
      int mid = (l + r) / 2;
      if (a[i] + b[mid] <= k)
        l = mid;
      else
        r = mid;
    }
    ans = max(ans, i + l);
  }
  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 ii = pair<ll, ll>;

const int MAX{200010};
const ll MOD{1000000007}, oo{1LL << 62};

ll solve(ll N, ll M, ll K, const vector<ll> &xs, const vector<ll> &ys) {
  ll ans = 0, sum = 0, a = 0, b = 0, c = 0;

  while (a < N and (sum + xs[a] <= K)) {
    ++c;
    sum += xs[a++];
  }

  while (b < M and (sum + ys[b] <= K)) {
    sum += ys[b++];
    ++c;
  }

  ans = c;
  --a;

  while (a >= 0) {
    sum -= xs[a--];
    --c;

    while (b < M and (sum + ys[b] <= K)) {
      sum += ys[b++];
      ++c;
    }

    ans = max(ans, c);
  }

  return ans;
}

int main() {
  ios::sync_with_stdio(false);

  ll N, M, K;
  cin >> N >> M >> K;

  vector<ll> xs(N), ys(M);

  for (int i = 0; i < N; ++i)
    cin >> xs[i];

  for (int i = 0; i < M; ++i)
    cin >> ys[i];

  auto ans = max(solve(N, M, K, xs, ys), solve(M, N, K, ys, xs));

  cout << ans << '\\n';

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX{200010};
const ll MOD{1000000007}, oo{1LL << 62};

ll solve(ll N, ll M, ll K, const vector<ll> &xs, const vector<ll> &ys) {
  ll ans = 0, sum = 0, a = 0, b = 0, c = 0;

  while (a < N and (sum + xs[a] <= K)) {
    ++c;
    sum += xs[a++];
  }

  while (b < M and (sum + ys[b] <= K)) {
    sum += ys[b++];
    ++c;
  }

  ans = c;
  --a;

  while (a >= 0) {
    sum -= xs[a--];
    --c;

    while (b < M and (sum + xs[b] <= K)) {
      sum += ys[b++];
      ++c;
    }

    ans = max(ans, c);
  }

  return ans;
}

int main() {
  ios::sync_with_stdio(false);

  ll N, M, K;
  cin >> N >> M >> K;

  vector<ll> xs(N), ys(M);

  for (int i = 0; i < N; ++i)
    cin >> xs[i];

  for (int i = 0; i < M; ++i)
    cin >> ys[i];

  auto ans = max(solve(N, M, K, xs, ys), solve(M, N, K, ys, xs));

  cout << ans << '\\n';

  return 0;
}
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++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main() {
  int n, m, k, tmp, ans;
  ans = 0;
  cin >> n >> m >> k;
  vector<ll> sum_a(n + 1, 0), sum_b(m + 1, 0);
  rep(i, n) {
    cin >> tmp;
    sum_a[i + 1] = sum_a[i] + tmp;
  }
  rep(i, m) {
    cin >> tmp;
    sum_b[i + 1] = sum_b[i] + tmp;
  }
  auto lim_a = upper_bound(sum_a.begin(), sum_a.end(), k);
  for (auto itr_a = sum_a.begin(); itr_a != lim_a; itr_a++) {
    int dist = int(--upper_bound(sum_b.begin(), sum_b.end(), k - *itr_a) -
                   sum_b.begin() + itr_a - sum_a.begin());
    ans = max(dist, ans);
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main() {
  int n, m, k, tmp, ans;
  cin >> n >> m >> k;
  vector<ll> sum_a(n + 1, 0), sum_b(m + 1, 0);
  rep(i, n) {
    cin >> tmp;
    sum_a[i + 1] = sum_a[i] + tmp;
  }
  rep(i, m) {
    cin >> tmp;
    sum_b[i + 1] = sum_b[i] + tmp;
  };

  ans = 0;
  rep(i, n + 1) {
    if (sum_a[i] > k)
      break;
    rep(j, m + 1) {
      if (sum_a[i] + sum_b[j] <= k)
        ans = max(ans, i + j);
      else
        break;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  long long k;
  cin >> n >> m >> k;
  vector<long long> a(n + 1);
  a.push_back(0);
  int a_n;
  rep2(i, 1, n + 1) {
    cin >> a_n;
    a[i] = (i == 0) ? a_n : a_n + a[i - 1];
  }
  vector<long long> b(m + 1);
  b.push_back(0);
  int b_n;
  rep2(i, 1, m + 1) {
    cin >> b_n;
    b[i] = (i == 0) ? b_n : b_n + b[i - 1];
  }
  int ans = 0;
  int j = m;
  for (int i = 0; i <= n; i++) {
    if (a[i] > k)
      break;
    while (b[j] > k - a[i]) {
      j -= 1;
    }
    ans = max(ans, i + j);
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  long long k;
  cin >> n >> m >> k;
  vector<long long> a(n);
  rep(i, n) { cin >> a[i]; }
  vector<long long> b(m);
  rep(i, m) { cin >> b[i]; }
  ll cnt = 0;
  int i_a = 0;
  int i_b = 0;
  while (cnt < n + m) {
    if (i_a >= n && i_b >= m)
      break;
    else if (i_a >= n) {
      k -= b[i_b];
      if (k < 0)
        break;
      i_b++;
      cnt++;
    } else if (i_b >= m) {
      k -= a[i_a];
      if (k < 0)
        break;
      i_a++;
      cnt++;
    } else {
      if (a[i_a] < b[i_b]) {
        k -= a[i_a];
        if (k < 0)
          break;
        cnt++;
        i_a++;
      } else if (a[i_a] > b[i_b]) {
        k -= b[i_b];
        if (k < 0)
          break;
        i_b++;
        cnt++;
      } else {
        if (a[i_a + 1] < a[i_b + 1]) {
          k -= a[i_a];
          if (k < 0)
            break;
          cnt++;
          i_a++;
        } else {
          k -= b[i_b];
          if (k < 0)
            break;
          cnt++;
          i_b++;
        }
      }
    }
  }
  cout << cnt << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
template <class T = ll> inline T in(istream &is = cin) {
  T ret;
  is >> ret;
  return ret;
}
template <class T>
inline auto vec2(class vector<T>::size_type h, class vector<T>::size_type w,
                 T v = T()) {
  return vector<vector<T>>(h, vector<T>(w, v));
}
template <class RandomAccessIterator>
inline void psortb(RandomAccessIterator first, RandomAccessIterator last) {
  using P = pair<decltype(first->first), decltype(first->second)>;
  sort(first, last, [](const P &p1, const P &p2) {
    return p1.second < p2.second ||
           (p1.second == p2.second && p1.first < p2.first);
  });
}

int main() {
  ll n = in(), m = in(), k = in();
  vector<ll> sa(n + 1), sb(m + 1);
  for (ll i = 0; i < n; ++i)
    sa[i + 1] = in() + sa[i];
  for (ll i = 0; i < m; ++i)
    sb[i + 1] = in() + sb[i];

  ll ans = 0;

  ll idxa = n, idxb = 0;
  while (idxa >= 0 && idxb <= m) {
    if (sa[idxa] > k) {
      --idxa;
    } else if (sa[idxa] + sb[idxb] <= k) {
      ans = max(ans, idxa + idxb);
      idxb++;
    } else {
      --idxa;
    }
  }

  idxa = 0, idxb = m;
  while (idxa <= n && idxb >= 0) {
    if (sb[idxb] > k) {
      --idxb;
    } else if (sa[idxa] + sb[idxb] <= k) {
      ans = max(ans, idxa + idxb);
      idxa++;
    } else {
      --idxb;
    }
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
template <class T = ll> inline T in(istream &is = cin) {
  T ret;
  is >> ret;
  return ret;
}
template <class T>
inline auto vec2(class vector<T>::size_type h, class vector<T>::size_type w,
                 T v = T()) {
  return vector<vector<T>>(h, vector<T>(w, v));
}
template <class RandomAccessIterator>
inline void psortb(RandomAccessIterator first, RandomAccessIterator last) {
  using P = pair<decltype(first->first), decltype(first->second)>;
  sort(first, last, [](const P &p1, const P &p2) {
    return p1.second < p2.second ||
           (p1.second == p2.second && p1.first < p2.first);
  });
}

int main() {
  ll n = in(), m = in(), k = in();
  vector<ll> sa(n + 1), sb(m + 1);
  for (ll i = 0; i < n; ++i)
    sa[i + 1] = in() + sa[i];
  for (ll i = 0; i < m; ++i)
    sb[i + 1] = in() + sb[i];

  ll ans = 0;

  ll idxa = n, idxb = 0;
  while (idxa >= 0 && idxb <= m) {
    if (sa[idxa] > k) {
      --idxa;
    } else if (sa[idxa] + sb[idxb] <= k) {
      ans = max(ans, idxa + idxb);
      idxb++;
    } else {
      --idxa;
    }
  }

  idxa = 0, idxb = m;
  while (idxa <= n && idxb >= 0) {
    if (sa[idxb] > k) {
      --idxb;
    } else if (sa[idxa] + sb[idxb] <= k) {
      ans = max(ans, idxa + idxb);
      idxa++;
    } else {
      --idxb;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  long n, m, k;
  cin >> n >> m >> k;
  vector<long> a(n), b(m);
  rep(i, n) { cin >> a.at(i); }
  rep(i, m) { cin >> b.at(i); }
  long tot = 0;
  long p = 0;
  long q = -1;
  rep(i, n) {
    if (tot + a.at(i) <= k) {
      tot += a.at(i);
      p = i + 1;
      q = i;
    } else {
      break;
    }
  }
  long ans = p;
  long now = 0;

  while (now < m) {
    if (tot + b[now] <= k) {
      tot += b.at(now);
      p++;
      now++;
      ans = max(ans, p);

    } else {
      if (q >= 0) {
        tot -= a.at(q);
        q--;
        p--;
        ans = max(ans, p);
      } else {

        ans = max(ans, p);
        break;
      }
    }
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  long n, m, k;
  cin >> n >> m >> k;
  vector<long> a(n), b(m), c(n + m);
  rep(i, n) {
    cin >> a.at(i);
    c.at(n + m - i - 1) = a.at(i);
  }
  rep(i, m) {
    cin >> b.at(i);
    c.at(n + i) = b.at(i);
  }
  long tot = 0;
  long p = 0;
  long q = 0;
  rep(i, n) {
    if (tot + a.at(i) <= k) {
      tot += a.at(i);
      p = i + 1;
      q = i;
    } else {
      break;
    }
  }
  long ans = p;
  long now = 0;

  while (now < m && q >= 0) {
    if (tot + b[now] <= k) {
      tot += b.at(now);
      p++;
      now++;
      ans = max(ans, p);

    } else {

      tot -= a.at(q);
      q--;

      ans = max(ans, p);
      p--;
    }
  }
  long sum = 0;
  long t = 0;
  long ans2 = 0;
  long st = 0;
  long i = 0;
  rep(i, m) {

    while (sum < k && t < m) {
      sum += b.at(t);
      t++;
    }
    if (sum > k) {
      i++;
      sum -= b.at(i);
    }
    ans2 = max(ans2, t - i + 1);
    sum -= b.at(i);
    i++;
  }

  cout << ans << endl;
}