#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < q; ++i) {
        int l, r, k;
        cin >> l >> r >> k;
        l--;
        ll ans = 0;
        for (int j = l; j + k <= r; ++j) {
            ans += *min_element(a.begin() + j, a.begin() + j + k);
        }
        cout << ans << '\n';
    }
}
