#include #include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using S = vector; S op(S a, S b) { for (int i : b) a.push_back(i); sort(a.begin(), a.end()); while (a.size() > 10) a.pop_back(); return a; } S e() { return S(); } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n, q; cin >> n >> q; atcoder::segtree seg(n); rep(i, n) { int s; cin >> s; seg.set(i, {s}); } while (q--) { int l, r, k; cin >> l >> r >> k; l--; ll ans = 0; S x = seg.prod(l, r); rep(i, k) ans += x[i]; cout << ans << endl; } return 0; }