Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <random>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define per(i, a, n) for (int i = n - 1; i >= a; --i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef int64_t i64;
typedef uint64_t ui64;
typedef pair<int, int> pi;

struct custom_hash {
  static ui64 splitmix64(ui64 x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }

  size_t operator()(ui64 x) const {
    static const ui64 FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

template <class T, class U>
inline ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << ' ' << p.second;
  return os;
}
template <class T, class U>
inline istream &operator>>(istream &os, pair<T, U> &p) {
  os >> p.first >> p.second;
  return os;
}
template <class T> inline ostream &operator<<(ostream &os, const vector<T> &v) {
  if (v.empty())
    return os;
  if (v.begin() != v.end())
    os << v.front();
  for (auto it = ++v.begin(); it != v.end(); ++it)
    os << ' ' << *it;
  return os;
}
template <class T> inline istream &operator>>(istream &is, vector<T> &v) {
  for (auto &i : v)
    is >> i;
  return is;
}

template <class T, size_t N>
inline istream &operator>>(istream &is, array<T, N> &a) {
  for (auto &i : a)
    is >> i;
  return is;
}

inline void Solve(istream &is, ostream &os) {
  int n, m;
  is >> n;
  vi times(n);
  is >> times >> m;
  vector<pi> drinks(m);
  is >> drinks;

  int sum = accumulate(all(times), 0);
  for (const auto drink : drinks) {
    os << sum + drink.first - times[drink.second - 1] << '\n';
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << setprecision(20) << fixed;
  Solve(cin, cout);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <random>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define per(i, a, n) for (int i = n - 1; i >= a; --i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef int64_t i64;
typedef uint64_t ui64;
typedef pair<int, int> pi;

struct custom_hash {
  static ui64 splitmix64(ui64 x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }

  size_t operator()(ui64 x) const {
    static const ui64 FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

template <class T, class U>
inline ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << ' ' << p.second;
  return os;
}
template <class T, class U>
inline istream &operator>>(istream &os, pair<T, U> &p) {
  os >> p.first >> p.second;
  return os;
}
template <class T> inline ostream &operator<<(ostream &os, const vector<T> &v) {
  if (v.empty())
    return os;
  if (v.begin() != v.end())
    os << v.front();
  for (auto it = ++v.begin(); it != v.end(); ++it)
    os << ' ' << *it;
  return os;
}
template <class T> inline istream &operator>>(istream &is, vector<T> &v) {
  for (auto &i : v)
    is >> i;
  return is;
}

template <class T, size_t N>
inline istream &operator>>(istream &is, array<T, N> &a) {
  for (auto &i : a)
    is >> i;
  return is;
}

inline void Solve(istream &is, ostream &os) {
  int n, m;
  is >> n;
  vi times(n);
  is >> times >> m;
  vector<pi> drinks(m);
  is >> drinks;

  int sum = accumulate(all(times), 0);
  for (const auto drink : drinks) {
    os << sum + drink.second - times[drink.first - 1] << '\n';
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << setprecision(20) << fixed;
  Solve(cin, cout);
  return 0;
}