#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 p(n + 1, 0); for (i64 x : v) { i64 b; for (i64 i = 1; true; i++) { if (x / i < i) { b = x / i; break; } i64 i1 = lower_bound(s.begin(), s.end(), (p2){i, 0}) - s.begin(); i64 i2 = lower_bound(s.begin(), s.end(), (p2){i + 1, 0}) - s.begin(); p[i1] += x / i; p[i2] -= x / i; } for (i64 i = b; i >= 1; i--) { i64 l = x / (i + 1) + 1, r = x / i + 1; assert(x / l <= i); assert(x / r < i); i64 i1 = lower_bound(s.begin(), s.end(), (p2){l, 0}) - s.begin(); i64 i2 = lower_bound(s.begin(), s.end(), (p2){r, 0}) - s.begin(); p[i1] += i; p[i2] -= i; } } for (i64 i = 1; i <= n; i++) p[i] += p[i - 1]; vector ans(n); for (i64 i = 0; i < n; i++) ans[s[i].second] = p[i]; for (i64 x : ans) cout << x << "\n"; }