Problem p02623 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                 \\
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(    \\
            c i) {
sim > struct rge {
  c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define mx 1000002
mt19937 myrand(time(0));

int main() {
  ios::sync_with_stdio(0);
  cin.tie(), cout.tie();
  ll n, m, k;
  cin >> n >> m >> k;
  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> cum(m, 0);
  for (int i = 0; i < m; i++) {
    cum[i] = b[i];
    if (i != 0)
      cum[i] += cum[i - 1];
  }
  ll ans = 0, cur = 0;
  for (int i = 0; i < n; i++) {
    if (cur > k)
      break;
    ll id = upper_bound(all(cum), k - cur) - cum.begin();
    ans = max(ans, i + id);
    cur += a[i];
  }
  if (cur <= k) {
    ll id = upper_bound(all(cum), k - cur) - cum.begin();
    ans = max(ans, n + id);
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                 \\
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(    \\
            c i) {
sim > struct rge {
  c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define mx 1000002
mt19937 myrand(time(0));

int main() {
  ios::sync_with_stdio(0);
  cin.tie(), cout.tie();
  ll n, m, k;
  cin >> n >> m >> k;
  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> cum(n + 1, 0);
  for (int i = 0; i < m; i++) {
    cum[i] = b[i];
    if (i != 0)
      cum[i] += cum[i - 1];
  }
  ll ans = 0, cur = 0;
  for (int i = 0; i < n; i++) {
    if (cur > k)
      break;
    ll id = upper_bound(all(cum), k - cur) - cum.begin();
    id--;
    if (id >= 0) {
      ans = max(ans, i + id + 1);
    }
    cur += a[i];
  }
  if (cur <= k) {
    ll id = upper_bound(all(cum), k - cur) - cum.begin();
    id--;
    if (id >= 0) {
      ans = max(ans, n + id + 1);
    }
  }
  cout << ans << endl;
  return 0;
}