#include <atcoder/scc>;
#include <atcoder/convolution>
#include <atcoder/modint>
#include <atcoder/math>
#include <atcoder/fenwicktree>
#include <atcoder/dsu>
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using namespace atcoder;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll mod = 998244353;
int main() {
	ll N, Q;
	cin >> N >> Q;
	vector<ll> t(Q);
	vector<ll> u(Q);
	vector<ll> v(Q);
	fenwick_tree<long long> fw(N);
	rep(i, N) {
		ll a;
		cin >> a;
		fw.add(i, a);
	}
	rep(i,Q) {
		cin >> t.at(i) >> u[i] >> v[i];

	}

	rep(i, Q) {
		if (t[i] == 0) {
			fw.add(u[i], v[i]);
		}
		else {
			cout << fw.sum(u[i], v[i]) << endl;;
		}
	}
}
#define FILEIO(a) freopen(a".in", "r", stdin); freopen(a".out", "w", stdout);
#include <cstdio>
#include <algorithm>
#include <numeric>

typedef long long ll;

const int MaxN = 100005;

inline int div_ceil(ll a, int b) {
	return (a + b - 1) / b;
}

int n, W;
struct node {
	int b, l, r; ll val;
	
	node() = default;
	node(int b, int l, int r): b(b), l(l), r(r) {
		val = (ll)r * (W - b) + (ll)l * b;
	}
	
	inline int calc(ll s) const {
		if (s >= val) return W;
		ll tmp = s - (ll)b * l;
		return tmp > 0 ? b + div_ceil(tmp, r) : div_ceil(s, l);
	}
} dat[MaxN];

ll solve() {
	scanf("%d%d", &n, &W);
	
	ll sum = 0;
	for (int i = 0; i < n; ++i) {
		int b, l, r;
		scanf("%d%d%d", &b, &l, &r);
		dat[i] = node(b, l, r);
		sum -= (ll)l * b;
	}
	
	std::sort(dat, dat + n, [](const node &a, const node &b) {
		return a.val > b.val;
	});
	
	for (int i = 0; i < n; ++i) {
		ll val = dat[i].val;
		if (sum + val >= 0) {
			int res = W;
			for (int j = 0; j < i; ++j) {
				res = std::min(res, dat[j].calc(-sum + dat[j].val - val));
			}
			for (int j = i; j < n; ++j) {
				res = std::min(res, dat[j].calc(-sum));
			}
			return (ll)i * W + res;
		}
		sum += val;
	}
	
	return (ll)n * W;
}

int main() {
	printf("%lld\n", solve());
	return 0;
}