#include<bits/stdc++.h>
#include<math.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define MOD 1000000007LL
#define ROD 1000000000
#define INF 12345678
#define MIN(a,b) (a>b?b:a)
using namespace std;
#include<bits/stdc++.h>
#include<math.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define ll long long
#define mp make_pair
#define  piii pair<pair<ll,ll>,pair <ll,ll>>
#define pii pair <ll,ll>
#define fi first
#define se second
ll ch(ll);
ll n,cr[100005],tot,x;
piii br[100005];
int main()
{
	cin>>n>>x;
	rep(i,0,n)
	{
		cin>>br[i].fi.se>>br[i].se.fi>>br[i].se.se;
		br[i].fi.fi=(br[i].se.se)*(x-br[i].fi.se)+br[i].fi.se*br[i].se.fi;
		tot+=br[i].fi.se*br[i].se.fi;
	}
	//cout<<tot<<"\n";
	sort(br,br+n,greater <piii> ());
	rep(i,0,n)
	{
		cr[i]=br[i].fi.fi;
		if(i-1>=0)
		cr[i]+=cr[i-1];
	}
	cr[n]=cr[n-1];
	// rep(i,0,n+1)
	// cout<<cr[i]<<" ";
	// rep(i,0,n)
	// cout<<br[i].fi.se<<" "<<br[i].se.fi<<" "<<br[i].se.se<<" "<<cr[i]<<"\n";
	ch(2497);
	ll low=0,high=n*x,mid,ans;
	while(low<=high)
	{
		mid=(low+high)/2;
		if(ch(mid))
		{
			ans=mid;
			high=mid-1;
		}
		else
			low=mid+1;
	}
	//cout<<ch(400)<<" ";
	cout<<ans;
}
ll ch(ll mid)
{
	ll q=mid/x,r=mid-x*q;
	if(mid==n*x)
		return 1;
	//cout<<r<<" ";
	rep(i,0,n)
	{
		ll temp=0;
		if(i<q)
		{
			if(q>=0)
			temp+=cr[q]-br[i].fi.fi;
			//temp+=(r>br[i].fi.se?r*br[i].se.se:r*br[i].se.fi);
			temp+=(r>br[i].fi.se?(r-br[i].fi.se)*br[i].se.se+br[i].fi.se*br[i].se.fi:r*br[i].se.fi);		
		}
		else
		{
			if(q-1>=0)
			temp+=cr[q-1];
			temp+=(r>br[i].fi.se?(r-br[i].fi.se)*br[i].se.se+br[i].fi.se*br[i].se.fi:r*br[i].se.fi);		
			//cout<<"HERE"<<br[i].fi.se<<" "<<r<<" "<<r-br[i].fi.se<<" "<<br[i].se.se<<" ";
		}
		// ll qw=r>br[i].fi.se?(r-br[i].fi.se)*br[i].se.se+br[i].fi.se*br[i].se.fi:r*br[i].se.fi;
		// cout<<mid<<" "<<tot<<" "<<qw<<" "<<r<<" "<<" "<<temp<<"\n";
		if(temp>=tot)
			return 1;
	}
	return 0;
}
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
template<typename T>
struct BIT{
    //1-index
    //0-indexで取ると無限ループする
    private:
    V<T> arr;
    int n;

    public:
    BIT(int siz){
        n=siz;
        arr.assign(n+1,0);
    }
    //一点更新 aにvを加える
    void add(T a,T v){
        //x+=(x&-x) 初項a,それ以降a<=2^Nが列挙
        for(T x=a;x<=n;x+=(x&-x)){
            arr[x]+=v;
        }
    }
    T sum(T a){
        // 1からaまでの区間和
        T ret=0;
        for(T x=a;x>0;x-=(x&-x))ret+=arr[x];
        return ret;
    }
    T get(T x){//x番目に大きい数　// 区間和がw以上となる最小のindを返す
        if(x<=0) return 0;
        T N=1;
        while(N*2<=n)N*=2;
        T v=0;
        for(T i=N;i>0;i/=2){
            if(v+i<=n&&arr[v+i]<x){
                x-=arr[v+i];
                v+=i;
            }
        }
        return v+1;
    }
    T query(int l,int r){
        return sum(r)-sum(l);
    }
};
int main(){
    int n,q;
    cin>>n>>q;
    BIT<ll> bit(n+5);
    ll a;
    for(int i=0;i<n;i++){
        cin>>a;
        bit.add(i+1,a);
    }
    ll t,l,r;
    while(q--){
        cin>>t>>l>>r;
        if(t){
            cout<<bit.query(l,r)<<"\n";
        }else{
            bit.add(l+1,r);
        }
    }   
}