#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int INF = 1e9;

struct MinSegmentTree {
    int n;
    vector<int> t;

    explicit MinSegmentTree(const vector<int>& a) : n(a.size()), t(2 * a.size()) {
        for (int i = 0; i < n; ++i) {
            t[i + n] = a[i];
        }
        for (int i = n - 1; i > 0; --i) {
            t[i] = min(t[i * 2], t[i * 2 + 1]);
        }
    }

    int get(int l, int r) const {
        int res = INF;
        l += n;
        r += n;
        while (l < r) {
            if (l & 1) {
                res = min(res, t[l++]);
            }
            if (r & 1) {
                res = min(res, t[--r]);
            }
            l /= 2;
            r /= 2;
        }
        return res;
    }
};

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];
    }
    MinSegmentTree st(a);
    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 += st.get(j, j + k);
        }
        cout << ans << '\n';
    }
}
