#include using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; vector p(n); for(int i = 0; i < n; ++i){ cin >> p[i]; } sort(p.begin(), p.end()); vector bottom_sums(n+1); uint64_t sum = 0; for(int i = 0; i <= n; ++i){ bottom_sums[i] = sum; sum += p[i]; } for(int i = 0; i < q; ++i){ int x, y; cin >> x >> y; uint64_t ans = bottom_sums[n - x + y] - bottom_sums[n - x]; cout << ans << '\n'; } cout << flush; return 0; }