#include <bits/stdc++.h>

#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define fi first
#define se second

#define For(i, a, b) for (int i = a; i <= b; i++)
#define ForRL(i, a, b) for (int i = a; i >= b; i--)
#define rep(i, n) for (int i = 0; i < n; i++)
#define repRL(i, n) for (int i = (n) - 1; i >= 0; i--)
#define pb push_back
#define coutE(x) {cout << x; exit(0);}
#define cinStr(x, n) cin >> x; x = ' ' + x; n = x.size() - 1;

#define Bitcnt(x) __builtin_popcount(x)
#define all(x) x.begin(), x.end()
#define bs binary_search
#define ub upper_bound
#define lb lower_bound
#define endl '\n'

#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>

using namespace std;

const int N = 1e5 + 5;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const long long LINF = 1e18;

const int B = 320;

const int dx[] = {1, 0, 0, -1};
const int dy[] = {0, 1, -1, 0};

mt19937_64 rng(time(0));

void file(string s){

    if (s.empty()) return;

    freopen((s + ".inp").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

struct query{
	int l, r, t, i;
	
	bool operator < (query &q){
		if (l/B != q.l/B) return l/B < q.l/B;
		return r < q.r;
	}
};

int n, q, a[N];
int x, y, cur;
int ans[N];
int sumB[B + 5], cntB[B + 5], cnt[B + 5][B + 5];
vector<query> quer;

void add(int x){
	
	int block = x/B;
	sumB[block] += x; cntB[block]++;
	cnt[block][x % B]++;
}

void remove(int x){
	
	int block = x/B;
	sumB[block] -= x; cntB[block]--;
	cnt[block][x % B]--;
}

void MO(query Q){
	
	int l = Q.l, r = Q.r, t = Q.t, i = Q.i;
	
	while (l < x) add(a[--x]);
	while (y < r) add(a[++y]);
	while (x < l) remove(a[x++]);
	while (r < y) remove(a[y--]);
	
	int res = 0;
	For(block, 0, B){
		
		if (t >= sumB[block]) t -= sumB[block], res += cntB[block];
		else{
			rep(tmp, B){
				
				int val = block * B + tmp;
				if (!val || val > t) continue;
				
				int v = min(cnt[block][tmp], t/val);
				
				res += v;
				t -= v * val;
			}
			
			break;
		}
	}
	
	ans[i] = res;
}

void solve(){

	cin >> n >> q;
	For(i, 1, n) cin >> a[i];
	
	rep(i, q){
		int l, r, t; cin >> l >> r >> t;
		quer.pb({l, r, t, i});
	}
	
	sort(all(quer));
	
	x = quer[0].l, y = quer[0].l - 1;
	for (query Q: quer) MO(Q);
	
	rep(i, q) cout << ans[i] << endl;
}


signed main(){

	fastIO; file("");

	solve();

	return 0;
}