import sys


def main():
    n, q = map(int, input().split())

    pref = [0] * (n + 1)
    pref2 = [0] * (n + 1)
    
    arr = list(map(int, input().split()))

    for i in range(1, n + 1):
        x = arr[i - 1]
        pref[i] = pref[i - 1] + x
        pref2[i] = pref2[i - 1] + x * x

    for _ in range(q):
        l, r, S = map(int, input().split())

        A = pref[r] - pref[l - 1]
        if A > S:
            print(-1)
            continue

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

        ans = A * rem + (A * A - B) // 2
        print(ans)


if __name__ == "__main__":
    main()
