#include<bits/stdc++.h> usingnamespacestd; typedeflonglong ll; #define pii pair<int, int> #define mk make_pair constint N = 1e6 + 10; constint mod = 998244353; intread() { int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0', c = getchar(); return x * f; }
intinc(int x, int y){ return (x + y >= mod) ? (x + y - mod) : (x + y); } intdel(int x, int y){ return (x - y < 0) ? (x - y + mod) : (x - y); } intqpow(int a, int x, int mo) { int res = 1; while (x) { if (x & 1) res = 1ll * a * res % mo; a = 1ll * a * a % mo;
x >>= 1; } return res; } int d[N]; int sum[N]; intmain() { int n = read(), m = read(); for (int i = 1; i <= n; i++) d[i] = read(); sort(1 + d, 1 + d + n); for (int i = 1; i <= n; i++) sum[i] = inc(sum[i - 1], d[i] % mod); for (int i = 1; i <= m; i++) { int a = read(), b = read(); int k = lower_bound(1 + d, 1 + d + n, b) - d; k--; int big = n - k; if (big < a) { puts("0"); } else { int ans = 0;
ans = inc(1ll * del(sum[n], sum[k]) * (big - a) % mod * qpow(big, mod - 2, mod) % mod, ans); ans = inc(1ll * sum[k] * (big + 1 - a) % mod * qpow(big + 1, mod - 2, mod) % mod, ans); cout << ans << endl; } } }