#include #include using namespace std; using isize = size_t; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; using i128 = __int128_t; using u128 = __uint128_t; using f64 = long double; using p2 = pair; using el = tuple; using mint = atcoder::modint998244353; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(18); _main(); } i64 pow(i64 x, i64 n) { i64 res = 1; i64 t = x; while (n > 0) { if (n & 1) res *= t; t *= t; n >>= 1; } return res; } i64 pow(i64 x, i64 n, i64 m) { i64 res = 1; i64 t = x % m; while (n > 0) { if (n & 1) res = res * t % m; t = t * t % m; n >>= 1; } return res; } void _main() { i64 n; cin >> n; vector s(n); for (i64 i = 0; i < n; i++) { cin >> s[i].first; s[i].second = i; } sort(s.begin(), s.end()); i64 q; cin >> q; vector v; i64 now = 0, sum = 0; for (;q--;) { i64 t, f; cin >> t >> f; if (now >= t) now += f, sum += f; else { v.push_back(sum); now = t + f; sum = f; } } if (sum > 0) v.push_back(sum); vector cnt(10000000, 0); vector cnts(10000000, 0); vector p; for (i64 x : v) { i64 b; for (i64 i = 1; true; i++) { if (x / i < i) { b = x / i; break; } if (i < cnt.size()) { cnt[i] += x / i; } else { p.push_back({i, x / i}); p.push_back({i + 1, -(x / i)}); } } for (i64 i = b; i >= 1; i--) { i64 l = x / (i + 1) + 1, r = x / i + 1; if (l < cnt.size()) cnts[l] += i; else p.push_back({l, i}); if (r < cnt.size()) cnts[r] -= i; else p.push_back({r, -i}); } } for (i64 i = 1; i < cnts.size(); i++) cnts[i] += cnts[i - 1]; sort(p.begin(), p.end()); i64 idx = 0; i64 ss = 0; vector ans(n, 0); for (auto [x, i] : s) { while (idx < p.size() && p[idx].first <= x) { ss += p[idx].second; idx++; } ans[i] = ss; if (x < cnt.size()) ans[i] += cnt[x] + cnts[x]; } for (i64 x : ans) cout << x << "\n"; }