alexjercan/bugnet huggingface dataset:
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

long long bin(long long table[], long long value, long long low,
              long long high) {

  long long upper_bound = high;

  while (low <= high) {
    long long mid = (low + high) / 2;
    if (table[mid] > value) {
      high = mid - 1;

    } else if (table[mid] < value) {
      low = mid + 1;

    } else {
      return mid;
    }
    // printf("%d %d\\n",checker1,checker2);
  }

  if (low >= upper_bound)
    return upper_bound - 1;
  else
    return low - 1;

  return -1;
}

int main() {
  long long n, m, k;
  scanf("%lli %lli %lli", &n, &m, &k);

  long long *table1 = new long long[n + 1];
  long long *table2 = new long long[m + 1];

  table1[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> table1[i];
    table1[i] += table1[i - 1];
  }

  table2[0] = 0;
  for (int i = 1; i <= m; i++) {
    cin >> table2[i];
    table2[i] += table2[i - 1];
  }

  long long count = 0;
  for (int i = 0; i < n + 1; i++) {
    long long rem = k - table1[i];

    if (rem < 0)
      continue;
    long long j = bin(table2, rem, 0, m);

    //	printf("%lli %lli %d\\n",rem,j,i);
    count = max(count, (i + j));
  }

  printf("%lli\\n", count);

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {

  long long n, m, k;
  scanf("%lli %lli %lli", &n, &m, &k);

  long long *table1 = new long long[n];
  long long *table2 = new long long[m];

  cin >> table1[0];
  for (int i = 1; i < n; i++) {
    cin >> table1[i];
    table1[i] += table1[i - 1];
  }

  cin >> table2[0];
  for (int i = 1; i < m; i++) {
    cin >> table2[i];
    table2[i] += table2[i - 1];
  }

  /*	for(int i=0;i<n;i++)printf("%lli ",table1[i]);
          printf("\\n");
          for(int i=0;i<m;i++)printf("%lli ",table2[i]);
          printf("\\n");

  */

  int total = 0;
  for (int i = 0; i < m; i++) {
    if (table2[i] > k) {
      total = i;
      break;
    }
  }

  for (int i = 0; i < n; i++) {
    int count = 0;
    if (table1[i] <= k) {
      count = i + 1;
      long long rem = k - table1[i];
      long long j = 0;
      while (table2[j] <= rem) {
        j++;
        if (j == m)
          break;
      }
      // printf("%lli %lli\\n",table1[i],table2[j-1]);
      count += j;
      // printf("%d\\n",count);
      total = max(total, count);
    } else
      break;
  }

  printf("%d\\n", total);

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

#include <bits/stdc++.h>
using namespace std;
long long int a1[200000];
long long int a2[200000];
int main() {
  long long int n, m, k;
  cin >> n >> m >> k;
  for (long long int i = 0; i < n; i++) {
    cin >> a1[i];
  }
  for (long long int i = 0; i < m; i++) {
    cin >> a2[i];
  }
  long long int p1[n + 1];
  long long int p2[m + 1];
  p1[0] = 0;
  p2[0] = 0;
  for (long long int i = 1; i <= n; i++) {
    p1[i] = p1[i - 1] + a1[i - 1];
  }
  for (long long int i = 1; i <= m; i++) {
    p2[i] = p2[i - 1] + a2[i - 1];
  }
  long long int res = 0;
  for (int i = 0; i <= n; i++) {
    long long int temp = k - p1[i];
    if (temp < 0) {
      break;
    }
    long long int in = lower_bound(p2, p2 + m + 1, temp) - p2;
    if (in == m + 1 || p2[in] > temp) {
      in--;
    }
    res = max(res, i + in);
  }
  cout << res;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int a1[200000];
int a2[200000];
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    cin >> a1[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> a2[i];
  }
  int i = 0;
  int j = 0;
  int t = 0;
  int bc = 0;
  while (i < n && j < m) {
    if (a1[i] < a2[j]) {
      if (t + a1[i] <= k) {
        t += a1[i];
        i += 1;
        bc += 1;
      }
    } else {
      if (t + a2[j] <= k) {
        t += a2[j];
        j += 1;
        bc += 1;
      }
    }
  }
  while (t < k && i < n) {
    if (t + a1[i] <= k) {
      t += a1[i];
      i += 1;
      bc += 1;
    }
  }
  while (t < k && j < m) {
    if (t + a2[j] <= k) {
      t += a2[j];
      j += 1;
      bc += 1;
    }
  }
  cout << bc;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

// #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <vector>
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
const int MAXN = 2e5 + 10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x & (-x))
using namespace std;
// getline(cin,s);
// set<ll>::iterator it;
// map<int,int>::iterator it;
// unordered_map
typedef long long ll;
ll a[MAXN], b[MAXN], sum1[MAXN], sum2[MAXN];
int main() {
  int n, m;
  ll k, ans = 0;
  scanf("%d %d %lld", &n, &m, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum1[i] = sum1[i - 1] + a[i];
  }
  for (int i = 1; i <= m; i++) {
    scanf("%lld", &b[i]);
    sum2[i] = sum2[i - 1] + b[i];
  }
  for (int i = 0; i <= n; i++) {
    if (k >= sum1[i]) {
      ll num = upper_bound(sum2 + 1, sum2 + 1 + m, k - sum1[i]) - sum2 - 1 + i;
      ans = max(ans, num);
    }
  }
  printf("%lld\\n", ans);
  return 0;
}

Error: 0

Fixed submission:

// #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <vector>
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
const int MAXN = 2e5 + 10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x & (-x))
using namespace std;
// getline(cin,s);
// set<ll>::iterator it;
// map<int,int>::iterator it;
// unordered_map
typedef long long ll;
int main() {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  queue<int> q1, q2;
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    q1.push(a);
  }
  for (int i = 1; i <= m; i++) {
    int b;
    scanf("%d", &b);
    q2.push(b);
  }
  int tot = 0, ans = 0;
  while (1) {
    int x = q1.front(), y = q2.front();
    if (x >= y) {
      tot += y;
      q2.pop();
    } else {
      tot += x;
      q1.pop();
    }
    if (tot > k)
      break;
    ans++;
    if (ans == n + m)
      break;
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

template <class T> void printIter(const T &a, string delimiter) {
  if (a.size() == 0)
    return;
  auto it = a.begin();
  cout << *it;
  it++;
  while (it != a.end()) {
    cout << delimiter << *it;
    it++;
  }
  cout << endl;
}

int main() {
  ll N, M;
  ll K;
  cin >> N >> M >> K;
  vector<ll> A(N);
  vector<ll> B(M);
  vector<ll> sumA(N);
  vector<ll> sumB(M);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    if (i == 0)
      sumA[0] = A[i];
    else
      sumA[i] = sumA[i - 1] + A[i];
  }
  for (int i = 0; i < M; ++i) {
    cin >> B[i];
    if (i == 0)
      sumB[0] = B[i];
    else
      sumB[i] = sumB[i - 1] + B[i];
  }
  ll m = 0;
  for (int i = 0; i < N; ++i) {
    ll k = sumA[i];
    ll tempm = 0;
    if (k > K)
      break;
    tempm = i + 1;
    auto it = upper_bound(sumB.begin(), sumB.end(), K - k);
    //        cout << k << ' ' << *(it-1) << endl;
    //        cout << tempm << ' ' << (ll)distance(sumB.begin(), it) << endl;
    tempm += (ll)distance(sumB.begin(), it);
    m = max(m, tempm);
  }
  auto it = upper_bound(sumB.begin(), sumB.end(), K);
  ll tempm = (ll)distance(sumB.begin(), it);
  m = max(m, tempm);
  cout << m << endl;
}


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


Fixed submission:

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

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vector<int> A(N);
  vector<int> B(N);
  vector<ll> sumA(N);
  vector<ll> sumB(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    if (i == 0)
      sumA[0] = A[i];
    else
      sumA[i] = sumA[i - 1] + A[i];
  }
  for (int i = 0; i < M; ++i) {
    cin >> B[i];
    if (i == 0)
      sumB[0] = B[i];
    else
      sumB[i] = sumB[i - 1] + B[i];
  }
  ll m = 0;
  for (int i = 0; i < N; ++i) {
    ll k = sumA[i];
    ll tempm = 0;
    if (k > K)
      break;
    tempm = i + 1;
    //        cout << k << endl;
    //        cout << tempm << endl;
    auto it = upper_bound(sumB.begin(), sumB.end(), K - k);
    //        cout << *it << endl;
    tempm += (int)distance(sumB.begin(), it);
    if (it == sumB.end() && *it == K - k) {
      tempm++;
    }
    //        cout << tempm << endl;
    m = max(m, tempm);
  }
  cout << m << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>

using namespace std;
int main() {
  int N, M, K;
  cin >> N >> M >> K;
  long long int A[N + 1], B[M + 1], a[N + 1], b[M + 1];
  int max = 0;
  long long int time = 0;
  int maxanum = 0;
  A[0] = 0;
  B[0] = 0;
  a[0] = 0;
  b[0] = 0;
  int j = M;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    time += A[i];
    a[i] = time;
  }
  time = 0;
  for (int i = 1; i <= M; i++) {
    cin >> B[i];
    time += B[i];
    b[i] = time;
  }
  for (int i = 0; i <= N; i++) {
    if (a[i] > K)
      break;
    while (b[j] > K - a[i]) {
      j -= 1;
    }
    if (max < i + j) {
      max = i + j;
    }
  }
  cout << max << endl;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;
int main() {
  int N, M, K;
  cin >> N >> M >> K;
  long long int A[N + 1], B[N + 1], a[N + 1], b[N + 1];
  int max = 0;
  long long int time = 0;
  int maxanum = 0;
  int maxbnum = 0;
  int count = 0;
  A[0] = 0;
  B[0] = 0;
  a[0] = 0;
  b[0] = 0;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    time += A[i];
    a[i] = time;
    if (time > K) {
      maxanum = i - 1;
      time = 0;
      break;
    }
    if (i == N) {
      maxanum = N;
      time = 0;
    }
  }
  for (int i = 1; i <= M; i++) {
    cin >> B[i];
    time += B[i];
    b[i] = time;
    if (time > K) {
      maxbnum = i - 1;
      time = 0;
      break;
    }
    if (i == M) {
      maxbnum = M;
      time = 0;
    }
  }
  cout << maxanum << endl;
  cout << maxbnum << endl;

  for (int anum = 0; anum <= maxanum; anum++) {
    time = a[anum];
    for (int i = maxbnum; i > max - anum; i--) {
      if (time + b[i] <= K) {
        count = anum + i;
        maxbnum = i;
        break;
      }
    }

    if (max < count) {
      max = count;
    }
    time = 0;
    count = 0;
  }
  cout << max << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

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


Error: TLE

Fixed submission:

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

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

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

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

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
const ll MOD = 1000000007;
const long long INF = 1LL << 60;
const double pi = acos(-1);

vector<ll> sumB;

// https://qiita.com/drken/items/97e37dd6143e33a64c8c
// めぐる式二分探索法

// 先に探索する配列をグローバル配列として宣言しておく必要がある。
//  index が条件を満たすかどうか
bool BinaryJudgeisOK(int index, ll key) {
  if (/*a[index] >= key*/ /*ここに条件式*/ sumB.at(index) <= key)
    return true;
  else
    return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(ll key) {
  // leftとrightのどちらがok,ngかは自分で判断する必要がある。
  int ok = -1; // 「index = 0」が条件を満たすこともあるので、初期値は -1
  int ng = (int)/*a*/ sumB.size(); // 「index =
                                   // a.size()-1」が条件を満たさないこともあるので、初期値は
                                   // a.size()

  /* ok と ng のどちらが大きいかわからないことを考慮 */
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;

    if (BinaryJudgeisOK(mid, key))
      ok = mid;
    else
      ng = mid;
  }
  // ok==-1||ok=配列変数.size()の時はその配列内に該当する値は存在しない。
  return ok;
  // 配列変数内に必ず該当する値が存在すると言えるときにのみ使える。
  // 使う場合はllに変えておいた方がいい
  // return 配列変数.at(ok);
}

int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  vector<ll> A(N);
  vector<ll> sumA(N + 1);
  vector<ll> B(M);
  sumB = vector<ll>(M + 1);
  rep(i, N) {
    cin >> A.at(i);
    sumA.at(i + 1) = A.at(i);
  }
  rep(i, M) {
    cin >> B.at(i);
    sumB.at(i + 1) = B.at(i);
  }
  for (int i = 1; i <= N; i++) {
    sumA.at(i) += sumA.at(i - 1);
  }
  for (int i = 1; i < M; i++) {
    sumB.at(i) += sumB.at(i - 1);
  }

  ll ans = 0;
  rep(i, N + 1) {
    int j = binary_search(K - sumA.at(i));
    if (j == -1)
      continue;
    ans = max(ans, (ll)i + j);
    // cout<<i<<" "<<j<<" "<<i+j<<endl;
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
const ll MOD = 1000000007;
const double pi = acos(-1);

int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  vector<ll> A(N);
  vector<ll> B(M);
  rep(i, N) { cin >> A.at(i); }
  rep(i, M) { cin >> B.at(i); }
  reverse(A.begin(), A.end());
  reverse(B.begin(), B.end());
  ll sum = 0, ans = 0;
  rep(i, N + M) {
    // cout<<sum<<endl;
    if (A.size() == 0 && B.size() == 0) {
      break;
    }
    if (A.size() == 0) {
      sum += B.at(B.size() - 1);
      ans++;
      B.pop_back();
      if (sum > K) {
        ans--;
        break;
      }
      continue;
    }
    if (B.size() == 0) {
      sum += A.at(A.size() - 1);
      ans++;
      A.pop_back();
      if (sum > K) {
        ans--;
        break;
      }
      continue;
    }
    if (A.at(A.size() - 1) <= B.at(B.size() - 1)) {
      sum += A.at(A.size() - 1);
      ans++;
      A.pop_back();
      if (sum > K) {
        ans--;
        break;
      }
    }
    if (A.at(A.size() - 1) > B.at(B.size() - 1)) {
      sum += B.at(B.size() - 1);
      ans++;
      B.pop_back();
      if (sum > K) {
        ans--;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long int n, m, k, f = 0, ax = 0, bx = 0, kx = 0;
  cin >> n >> m >> k;
  long long int a[n], b[m];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if ((kx + a[i] <= k) && f == 0) {
      ax++;
      kx += a[i];
    } else
      f = 1;
  }

  f = 0;
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    if ((kx + b[i] <= k) && f == 0) {
      bx++;
      kx += b[i];
    } else
      f = 1;
  }
  if (bx == m) {
    cout << n + m << endl;
    exit(0);
  }
  long long int ma = ax + bx;
  while (ax != 0) {
    ax--;
    kx -= a[ax];
    while (bx < m && kx + b[bx] <= k) {
      kx += b[bx];
      bx++;
    }
    ma = max(ma, ax + bx);
  }
  cout << ma << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long long int n, m, k, f = 0, ax = 0, bx = 0, kx = 0;
  cin >> n >> m >> k;
  long long int a[n], b[m];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if ((kx + a[i] <= k) && f == 0) {
      ax++;
      kx += a[i];
    } else
      f = 1;
  }

  f = 0;
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    if ((kx + b[i] <= k) && f == 0) {
      bx++;
      kx += b[i];
    } else
      f = 1;
  }
  if (bx == m) {
    cout << n + m << endl;
    exit(0);
  }
  ax = 0;
  bx = 0;
  kx = 0;
  long long int ma = 0;
  for (int i = 0; i <= n; i++) {
    ax = i;
    bx = 0;
    kx = 0;
    for (int ii = 0; ii < i; ii++) {
      kx += a[ii];
    }
    if (k < kx)
      break;
    for (int ii = 0; ii < m; ii++) {
      if (kx + b[ii] <= k) {
        kx += b[ii];
        bx++;
      } else {
        break;
      }
    }
    ma = max(ax + bx, ma);
  }
  cout << ma << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

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

  vector<long long> A(n), B(m);
  vector<long long> a(n + 1, 0), b(m + 1, 0);
  for (long long i = 0; i < n; i++) {
    cin >> A.at(i);
    // a[i] = 0;
  }
  for (long long i = 0; i < m; i++) {
    cin >> B.at(i);
    // b[i] = 0;
  }

  for (long long i = 1; i < n + 1; i++) {
    a[i] = a[i - 1] + A[i - 1];
    // a.push_back(a[i] + A[i]);
    // cout << A[i] << endl;
    // cout << a[i] << endl;
  }
  for (long long i = 1; i < m + 1; i++) {
    b[i] = b[i - 1] + B[i - 1];
    // b.push_back(b[i] + B[i]);
    // cout << b[i] << endl;
  }

  long long ans = 0, j = m;
  for (long long i = 0; i < n + 1; i++) {
    if (a[i] > k) {
      break;
    }
    while (b[j] > (k - a[i])) {
      j -= 1;
    }
    // cout << ans << endl;
    ans = max(ans, i + j);
    // cout << ans << endl;
  }
  cout << ans << endl;

  /*
  long long n,m,k;
  cin >> n >> m >> k;

  vector<long long> a(n);
  vector<long long> b(m);

  for(long long i=0; i<n; i++){
      cin >> a.at(i);
  }
  for(long long i=0; i<m; i++){
      cin >> b.at(i);
  }

  long long i=0,j=0;
  long long total=0;
  long long count=0;
  while(1){
      long long tmp = min(a[i],b[j]);
      total += tmp;
      if(tmp == a[i]){
          i++;
      }
      else{
          j++;
      }
      if(total > k){
          break;
      }
      else if(i==n&&j==m){
          count++;
          break;
      }
      count++;
  }
  cout << count << endl;
  */
  return 0;
}

Error: -6
malloc(): corrupted top size


Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

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

  for (long long i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (long long i = 0; i < m; i++) {
    cin >> b.at(i);
  }
  a[n + 1] = 10000000000;
  b[m + 1] = 10000000000;

  long long i = 0, j = 0;
  long long total = 0;
  long long count = 0;
  while (1) {
    long long tmp = min(a[i], b[j]);
    total += tmp;
    if (tmp == a[i]) {
      i++;
    } else {
      j++;
    }
    if (total > k) {
      break;
    } else if (i == n && j == m) {
      count++;
      break;
    }
    count++;
  }
  cout << count << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

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

vector<ll> A, B;

signed main() {
  ll N, M, K;
  cin >> N >> M >> K;
  A = vector<ll>(N);
  B = vector<ll>(M);
  for (ll i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (ll i = 0; i < M; i++) {
    cin >> B.at(i);
  }
  vector<ll> A_acm(N + 1, 0), B_acm(M + 1, 0);
  for (ll i = 1; i < N + 1; i++) {
    A_acm.at(i) += A_acm.at(i - 1) + A.at(i - 1);
  }
  for (ll i = 1; i < M + 1; i++) {
    B_acm.at(i) += B_acm.at(i - 1) + B.at(i - 1);
  }

  int max_book = 0;
  for (int a_i = 0, b_i = M; a_i < N + 1; a_i++) {
    if (K < A_acm.at(a_i)) {
      break;
    }
    while (K - A_acm.at(a_i) < B_acm.at(b_i)) {
      --b_i;
    }
    max_book = max(max_book, a_i + b_i);
  }
  cout << max_book << endl;

  return 0;
}

Error: 0

Fixed submission:

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

vector<ll> A, B;

signed main() {
  ll N, M, K;
  cin >> N >> M >> K;
  A = vector<ll>(N);
  B = vector<ll>(M);
  for (ll i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (ll i = 0; i < M; i++) {
    cin >> B.at(i);
  }
  for (ll i = 0; i < N - 1; i++) {
    A.at(i + 1) += A.at(i);
    if (K < A.at(i + 1)) {
      N = i + 1;
      break;
    }
  }
  for (ll i = 0; i < M - 1; i++) {
    B.at(i + 1) += B.at(i);
    if (K < B.at(i + 1)) {
      M = i + 1;
      break;
    }
  }

  int max_book = 0;
  for (int a_i = 0, b_i = M - 1; a_i < N; a_i++) {
    if (K < A.at(a_i)) {
      break;
    }
    while (K - A.at(a_i) < B.at(b_i)) {
      --b_i;
    }
    max_book = max(max_book, a_i + b_i + 2);
  }
  cout << max_book << endl;

  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++)
using namespace std;
using ll = long long;
const int INF = (1 << 30) - 1;
const long long LINF = (1LL << 62) - 1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int 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> sa(n + 1), sb(m + 1);
  rep(i, n) sa[i + 1] = a[i] + sa[i];
  rep(i, m) sb[i + 1] = b[i] + sb[i];
  ll ans = 0;
  rep(i, n + 1) {
    if (k - sa[i] < 0)
      break;
    auto it = upper_bound(sb.begin(), sb.end(), k - sa[i]);
    chmax(ans, i + it - sb.begin() - 1LL);
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1 << 30) - 1;
const long long LINF = (1LL << 62) - 1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  vector<ll> sa(n + 1), sb(m + 1);
  rep(i, n) sa[i + 1] = a[i] + sa[i];
  rep(i, m) sb[i + 1] = b[i] + sb[i];
  ll ans = 0;
  rep(i, n + 1) {
    if (k - sa[i] <= 0)
      break;
    auto it = upper_bound(sb.begin(), sb.end(), k - sa[i]);
    chmax(ans, i + it - sb.begin() - 1LL);
  }
  cout << ans << endl;
  return 0;
}