alexjercan/bugnet huggingface dataset:
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 REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
template <class A> void PR(A a, ll n) {
  rep(i, n) {
    if (i)
      cout << ' ';
    cout << a[i];
  }
  cout << "\\n";
}
ld PI = 3.14159265358979323846;

int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  vector<ll> A(N), B(M), AS(N + 1), BS(M + 1);
  rep(i, N) {
    cin >> A[i];
    // AS[i+1] = AS[i] + A[i];
  }
  rep(i, M) {
    cin >> B[i];
    // BS[i+1] = BS[i] + B[i];
  }
  ll sum = 0;
  ll id = 0;
  while (id < N && sum + A[id] <= K) {
    sum += A[id];
    id++;
  }
  ll r = 0;
  ll ans = 0;
  for (ll l = id - 1; l >= -1; l--) {
    while (r < M && sum + B[r] <= K) {
      sum += B[r];
      r++;
    }
    if (sum <= K) {
      cmax(ans, l + 1 + r);
    }
    sum -= A[l];
  }
  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 REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
template <class A> void PR(A a, ll n) {
  rep(i, n) {
    if (i)
      cout << ' ';
    cout << a[i];
  }
  cout << "\\n";
}
ld PI = 3.14159265358979323846;

int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  vector<ll> A(N), B(M), AS(N + 1), BS(M + 1);
  rep(i, N) {
    cin >> A[i];
    AS[i + 1] = AS[i] + A[i];
  }
  rep(i, M) {
    cin >> B[i];
    BS[i + 1] = BS[i] + B[i];
  }
  ll r = 0;
  ll sum = 0;
  ll ans = 0;
  rep(l, N + 1) {
    sum = AS[l];
    r = 0;
    while (r < M && sum + B[r] <= K) {
      sum += B[r];
      r++;
    }
    if (sum <= K) {
      cmax(ans, l + r);
    }
  }
  cout << ans << endl;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define all_acc(x) (x).begin(), (x).end(), 0LL
#define int long long
using namespace std;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
using ll = long long;

int accumulate(int *a, int n) { return accumulate(a, a + n, 0LL); }

int accumulate(vector<int> a) { return accumulate(a.begin(), a.end(), 0LL); }

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

  vector<int> A(n + 1), B(m + 1);
  A[0] = 0;
  B[0] = 0;
  for (int i = 1; i <= n; i++) {
    int ai;
    cin >> ai;
    A[i] = ai + A[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    int bi;
    cin >> bi;
    B[i] = bi + B[i - 1];
  }

  int ans = 0, j = m;

  for (int i = 0; i <= n; i++) {
    if (k < A[i])
      break;
    while (B[j] > k - A[i]) {
      j--;
    }
    ans = max(ans, i + j);
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define all_acc(x) (x).begin(), (x).end(), 0LL
#define int long long
using namespace std;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
using ll = long long;

int accumulate(int *a, int n) { return accumulate(a, a + n, 0LL); }

int accumulate(vector<int> a) { return accumulate(a.begin(), a.end(), 0LL); }

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

  vector<int> A(n + 1), B(m + 1);
  A[0] = 0;
  B[0] = 0;
  for (int i = 1; i <= n; i++) {
    int ai;
    cin >> ai;
    A[i] = ai + A[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    int bi;
    cin >> bi;
    B[i] = bi + B[i - 1];
  }

  int ans = 0;

  for (int i = 0; i <= n; i++) {
    if (k < A[i])
      break;
    int ki = k - A[i];
    int j = m;
    while (B[j] > ki) {
      j--;
    }

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

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

#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  vector<ll> a(N), b(M);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  for (int i = 0; i < M; i++)
    cin >> b[i];
  vector<ll> sa(N + 1);
  for (int i = 0; i < N; i++)
    sa[i + 1] += a[i] + sa[i];
  for (int i = 1; i < M; i++)
    b[i] += b[i - 1];
  b.push_back(LINF);
  ll ans = 0LL;
  for (ll i = 0; i <= N; i++) {
    ll d = K - sa[i];
    if (d >= 0LL) {
      ll ib = upper_bound(b.begin(), b.end(), d) - b.begin();
      ll tmp = i + ib;
      ans = max(ans, tmp);
    }
  }

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  vector<ll> a(N), b(M);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  for (int i = 0; i < M; i++)
    cin >> b[i];
  vector<ll> sa(N + 1);
  for (int i = 0; i < M; i++)
    sa[i + 1] += a[i] + sa[i];
  for (int i = 1; i < M; i++)
    b[i] += b[i - 1];
  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    ll d = K - sa[i];
    if (d >= 0) {
      ll ib = upper_bound(b.begin(), b.end(), d) - b.begin();
      ans = max(ans, i + ib);
    }
  }

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

#include "bits/stdc++.h"

#define ll long long
#define pb push_back
#define pii pair<ll, ll>
#define vpii vector<pii>
#define vi vector<ll>
#define vs vector<string>
#define vvi vector<vector<ll>>
#define inf 1'010'000'000'000'000'017LL
#define all(it, a) for (auto it = (a).begin(); it != (a).end(); it++)
#define sz(x) (ll) x.size()
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repr(i, a, b) for (ll i = a; i > b; i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define mp make_pair
#define whatis(x) cout << #x << " is " << x << "\\n";
#define graph(n) adj(n, vector<ll>())

using namespace std;

template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void Main() {
  ll N, M, K;
  cin >> N >> M >> K;
  vi A(N, 0), B(M, 0);
  rep(i, 0, N) cin >> A[i];
  rep(i, 0, M) cin >> B[i];

  vi canReadB(N + 1, 0);
  ll tempSumA = 0, tempSumB = 0;
  rep(i, 0, M) {
    if (B[i] + tempSumB > K)
      break;
    tempSumB += B[i];
    canReadB[0]++;
  }
  ll result = canReadB[0];
  rep(i, 1, N + 1) {
    if (A[i - 1] + tempSumA > K)
      break;
    tempSumA += A[i - 1];
    canReadB[i] = canReadB[i - 1];
    while (tempSumA + tempSumB > K) {
      canReadB[i]--;
      tempSumB -= B[canReadB[i]];
    }
    chmax(result, i + canReadB[i]);
  }

  cout << result << endl;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  Main();
  return 0;
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"

#define ll long long
#define pb push_back
#define pii pair<ll, ll>
#define vpii vector<pii>
#define vi vector<ll>
#define vs vector<string>
#define vvi vector<vector<ll>>
#define inf 1'010'000'000'000'000'017LL
#define all(it, a) for (auto it = (a).begin(); it != (a).end(); it++)
#define sz(x) (ll) x.size()
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repr(i, a, b) for (ll i = a; i > b; i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define mp make_pair
#define whatis(x) cout << #x << " is " << x << "\\n";
#define graph(n) adj(n, vector<ll>())

using namespace std;

template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void Main() {
  ll N, M, K;
  cin >> N >> M >> K;
  vi books(N + N + 10, 0);
  rep(i, 0, N + M) cin >> books[i];

  sort(books.begin(), books.end());

  ll result = 0, sumCost = 0;
  rep(i, 0, books.size()) {
    if (books[i] == 0)
      continue;
    if (sumCost + books[i] >= K)
      break;
    sumCost += books[i];
    result++;
  }

  cout << result << endl;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

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

#include <iostream>
#include <queue>
using namespace std;

long long n, a[200005], b[200005], m, k, ans, sumA[200005], sumB[200005];

long long bs(long long t) {
  if (t < sumB[1])
    return 0;
  if (t >= sumB[m])
    return m;

  long long l = 1, r = m;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (sumB[mid] <= t && sumB[mid + 1] > t)
      return mid;
    else if (sumB[mid] <= t)
      l = mid + 1;
    else
      r = mid - 1;
  }
  return -1;
}

int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sumA[i] = sumA[i - 1] + a[i];
  }
  for (int j = 1; j <= m; j++) {
    cin >> b[j];
    sumB[j] = sumB[j - 1] + b[j];
  }

  for (long long i = 0; (i <= n) && (sumA[i] <= k); i++) {
    long long t = k - sumA[i];
    long long pos = bs(t);
    ans = max(ans, i + pos);
  }
  cout << ans;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <queue>
using namespace std;

int n, a[200005], b[200005], m, k, ans;

int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int j = 1; j <= m; j++)
    cin >> b[j];
  queue<pair<int, pair<int, int>>> q;
  q.push({k, {1, 1}});
  while (!q.empty()) {
    int remTime = q.front().first;
    int i = q.front().second.first;
    int j = q.front().second.second;
    q.pop();

    if (remTime < 0)
      continue;
    ans = max(ans, i + j - 2);
    if (i <= n && remTime >= a[i])
      q.push({remTime - a[i], {i + 1, j}});
    if (j <= m && remTime >= b[j])
      q.push({remTime - b[j], {i, j + 1}});
  }
  cout << ans;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

// 6/28 バーチャル参加
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main() {
  ll 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> S(N + 1), T(M + 1);
  S[0] = 0;
  T[0] = 0;
  rep(i, N) S[i + 1] = S[i] + A[i];
  rep(i, M) T[i + 1] = T[i] + B[i];

  ll res = 0;
  for (ll i = 0; i <= N; i++) {
    ll tb = K - S[i];
    if (tb < 0)
      break;
    auto it = upper_bound(T.begin(), T.end(), tb);
    ll now = i + (it - T.begin()) - 1; // T[0]のぶん、1を引く。
    // printf("i, now, tb = %d, %d, %d\\n", i, now, tb);
    res = max(res, now);
  }

  // ll res = 0;
  // ll time = 0;
  // int a = 0, b = 0;
  // while (true) {
  //     if (a == N && b == M) {
  //         break;
  //     }
  //     else if (a == N) {
  //         time += B[b];
  //         b++;
  //         // res++;
  //     }
  //     else if (b == M) {
  //         time += A[a];
  //         a++;
  //         // res++;
  //     } else {
  //         if (A[a] <= B[b]) {
  //             time += A[a];
  //             a++;
  //             // res++;
  //         } else {
  //             time += B[b];
  //             b++;
  //             // res++;
  //         }
  //     }

  //     if (time <= K) {
  //         res++;
  //     } else {
  //         break;
  //     }
  // }

  cout << res << endl;
}

Error: WA

Fixed submission:

// 6/28 バーチャル参加
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main() {
  ll 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> S(N + 1), T(N + 1);
  S[0] = 0;
  T[0] = 0;
  rep(i, N) S[i + 1] = S[i] + A[i];
  rep(i, M) T[i + 1] = T[i] + B[i];

  ll res = 0;
  for (ll i = 0; i <= N; i++) {
    ll tb = K - S[i];
    if (tb < 0)
      break;
    auto it = upper_bound(T.begin(), T.end(), tb);
    ll now = i + (it - T.begin());
    // printf("i, now = %d, %d\\n", i, now);
    res = max(res, now);
  }

  // ll res = 0;
  // ll time = 0;
  // int a = 0, b = 0;
  // while (true) {
  //     if (a == N && b == M) {
  //         break;
  //     }
  //     else if (a == N) {
  //         time += B[b];
  //         b++;
  //         // res++;
  //     }
  //     else if (b == M) {
  //         time += A[a];
  //         a++;
  //         // res++;
  //     } else {
  //         if (A[a] <= B[b]) {
  //             time += A[a];
  //             a++;
  //             // res++;
  //         } else {
  //             time += B[b];
  //             b++;
  //             // res++;
  //         }
  //     }

  //     if (time <= K) {
  //         res++;
  //     } else {
  //         break;
  //     }
  // }

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

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define REP(i, n, N) for (ll i = (n); i < (N); i++)
// #define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl
#define vint vector<int>
#define INF 1e9

using namespace std;
typedef long long ll;

int main() {

  ll n, m, k;
  cin >> n >> m >> k;
  ll tmp;
  //    vint a(n);
  vector<ll> sum_a(n + 1, 0);
  REP(i, 1, n + 1) {
    cin >> tmp;
    sum_a[i] = sum_a[i - 1] + tmp;
  }
  //    vint b(m);
  vector<ll> sum_b(m + 1, 0);
  REP(i, 1, m + 1) {
    cin >> tmp;
    sum_b[i] = sum_b[i - 1] + tmp;
  }

  int ans = 0;
  int j = m;
  for (int i = 0; i < n + 1; i++) {
    if (sum_a[i] > k) {
      break;
    }
    while (sum_b[j] > k - sum_a[i]) {
      j -= 1;
    }
    ans = max(ans, i + j);
  }

  p(ans);

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define REP(i, n, N) for (ll i = (n); i < (N); i++)
// #define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl
#define vint vector<int>
#define INF 1e9

using namespace std;
typedef long long ll;

int main() {

  ll n, m, k;
  cin >> n >> m >> k;
  ll tmp;
  vint a(n);
  REP(i, 0, n) {
    cin >> tmp;
    a[i] = tmp;
  }
  vint b(n);
  REP(i, 0, m) {
    cin >> tmp;
    b[i] = tmp;
  }

  queue<tuple<int, int, int, ll>> bfs;

  if (a[0] <= k) {
    bfs.push(make_tuple(1, 0, 1, a[0]));
  }
  if (b[0] <= k) {
    bfs.push(make_tuple(0, 1, 1, b[0]));
  }
  int ans = 0;
  while (not bfs.empty()) {
    tuple<int, int, int, ll> tmp_tpl = bfs.front();
    ll &time = get<3>(tmp_tpl);
    int &next_a = get<0>(tmp_tpl);
    int &next_b = get<1>(tmp_tpl);
    int &book_num = get<2>(tmp_tpl);

    //        p(ans);

    if (next_a >= n or next_b >= m) {
      ans = max(ans, book_num + 1);
      bfs.pop();
      continue;
    }

    if (time + a[next_a] <= k) {
      bfs.push(make_tuple(next_a + 1, next_b, book_num + 1, time + a[next_a]));
    } else {
      ans = max(ans, book_num);
    }
    if (time + b[next_b] <= k) {
      bfs.push(make_tuple(next_a, next_b + 1, book_num + 1, time + b[next_b]));
    } else {
      ans = max(ans, book_num);
    }

    bfs.pop();
  }

  p(ans);

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

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

template <class T> istream &operator>>(istream &is, vector<T> &collection) {
  for (auto &item : collection)
    is >> item;
  return is;
}

void solution() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> as(n);
  vector<int> bs(m);
  cin >> as >> bs;

  vector<int64_t> sa(n);
  sa[0] = as[0];
  for (int i = 1; i < n; ++i) {
    sa[i] = sa[i - 1] + as[i];
  }

  vector<int64_t> sb(m);
  sb[0] = bs[0];
  for (int i = 1; i < m; ++i) {
    sb[i] = sb[i - 1] + bs[i];
  }

  int cb = m;
  int count = 0;
  for (int ca = 0; ca <= n; ++ca) {
    int64_t t = ca > 0 ? k - sa[ca - 1] : k;
    if (t < 0) {
      break;
    }
    for (; cb > 0; --cb) {
      if (t >= sb[cb - 1]) {
        count = max(count, ca + cb);
        break;
      }
    }
    count = max(count, ca);
  }
  cout << count << '\\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
  solution();
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

template <class T> istream &operator>>(istream &is, vector<T> &collection) {
  for (auto &item : collection)
    is >> item;
  return is;
}

void solution() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> as(n);
  vector<int> bs(m);
  cin >> as >> bs;

  vector<int64_t> sa(n);
  sa[0] = as[0];
  for (int i = 1; i < n; ++i) {
    sa[i] = sa[i - 1] + as[i];
  }

  vector<int64_t> sb(n);
  sb[0] = bs[0];
  for (int i = 1; i < n; ++i) {
    sb[i] = sb[i - 1] + bs[i];
  }

  int ca = 0;
  int cb = 0;
  int count = 0;
  rep(i, n) {
    if (sa[i] <= k) {
      ca = i + 1;
    } else {
      break;
    }
  }
  int64_t t = k;
  if (ca > 0) {
    t -= sa[ca - 1];
  }

  assert(t >= 0);
  rep(i, m) {
    while (ca > 0 && sb[i] > t) {
      ca--;
      t = k;
      if (ca > 0) {
        t -= sa[ca - 1];
      }
    }
    if (sb[i] <= t) {
      cb = i + 1;
      count = max(count, ca + cb);
    } else {
      break;
    }
  }

  cout << count << '\\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
  solution();
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
const ll INF = 999999999999999;
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1);
  vector<ll> b(m + 1);
  a.at(0) = 0;
  b.at(0) = 0;
  for (ll i = 1; i <= n; ++i) {
    cin >> a.at(i);
    a.at(i) += a.at(i - 1);
  }
  for (ll i = 1; i <= m; ++i) {
    cin >> b.at(i);
    b.at(i) += b.at(i - 1);
  }

  ll ans = 0;
  for (ll i = 0; i <= n; ++i) {
    if (a.at(i) > k)
      break;
    // k-a.at(i)より大きいbの値の中で一番左のイテレータitr
    auto itr = upper_bound(b.begin(), b.end(), k - a.at(i));
    ll id = itr - b.begin();
    if (id != 0)
      --id;
    // cout << id << endl;
    ans = max(ans, id + i);
    /*for(ll j=0;j<=m;++j){
      ll sum = a.at(i) + b.at(j);
      if( sum > k ) break;
      ans = max(ans,i+j);
    }*/
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
const ll INF = 999999999999999;
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1);
  vector<ll> b(m + 1);
  for (ll i = 1; i <= n; ++i) {
    cin >> a.at(i);
    a.at(i) += a.at(i - 1);
  }
  for (ll i = 1; i <= m; ++i) {
    cin >> b.at(i);
    b.at(i) += b.at(i - 1);
  }

  ll ans = 0;
  for (ll i = 0; i <= n; ++i) {
    if (a.at(i) > k)
      break;
    for (ll j = 0; j <= m; ++j) {
      ll sum = a.at(i) + b.at(j);
      if (sum > k)
        break;
      ans = max(ans, i + j);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  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];
  long long time = 0;
  for (int i = 0; i < m; i++)
    time += b[i];
  int j = m;
  int ans = 0;
  for (int i = 0; i < n + 1; i++) {
    while (j > 0 && time > k) {
      j--;
      time -= b[j];
    }
    if (time > k)
      break;
    ans = max(ans, i + j);
    time += a[i];
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  queue<int> a, b;
  for (int i = 0; i < n; i++) {
    int s;
    cin >> s;
    a.push(s);
  }
  for (int i = 0; i < m; i++) {
    int s;
    cin >> s;
    b.push(s);
  }
  int x = max(a.size(), b.size()) - min(a.size(), b.size());
  if (a.size() < b.size()) {
    for (int i = 0; i < x; i++) {
      a.push(2e9);
    }
  }
  if (a.size() > b.size()) {
    for (int i = 0; i < x; i++) {
      b.push(2e9);
    }
  }
  long long sum = 0;
  int ans = 0;
  while (sum < k) {
    if (a.front() >= b.front()) {
      if (sum + b.front() > k)
        break;
      sum += b.front();
      b.pop();
      ans++;
    } else {
      if (sum + a.front() > k)
        break;
      sum += a.front();
      a.pop();
      ans++;
    }
  }
  cout << ans << endl;
}