#include <bits/stdc++.h>

using namespace std;

using ll = long long;

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

    int n, q;
    cin >> n >> q;

    vector<ll> a(n);
    vector<ll> pref(n + 1), pref2(n + 1);

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        pref[i + 1] = pref[i] + a[i];
        pref2[i + 1] = pref2[i] + a[i] * a[i];
    }

    while (q--) {
        int l, r;
        ll S;
        cin >> l >> r >> S;

        ll A = pref[r] - pref[l - 1];
        if (A > S) {
            cout << -1 << '\n';
            continue;
        }

        ll B = pref2[r] - pref2[l - 1];
        ll rem = S - A;

        cout << A * rem + (A * A - B) / 2 << '\n';
    }
}
