#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<pii,int>
#define mpp make_pair
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int maxn=100005;
const int bl=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=20;
const int maxa=1000000;
const int root=3;
int power(int a,int n){
int res=1;
while(n){
if(n&1) res=res*a%mod;
a=a*a%mod;n>>=1;
}
return res;
}
const int iroot=power(3,mod-2);
const int base=101;
int n,m,k[maxn],s[maxn],t[maxn];
int cur[maxn];
vector<pii> p;
bool check(int x){
for(int i=1;i<=m;i++) cur[i]=k[i];
priority_queue<pii,vector<pii>,greater<pii>> pq;
int pre=0;
for(pii d:p){
int cnt=inf;
if((d.fi-pre)<inf/x) cnt=(d.fi-pre)*x;
while(cnt && !pq.empty()){
int id=pq.top().se;
int num=min(cur[id],cnt);
cnt-=num;cur[id]-=num;
if(cur[id]==0) pq.pop();
}
pre=d.fi;
if(d.se<0 && cur[-d.se]!=0) return false;
else if(d.se>0) pq.push({t[d.se],d.se});
}
return true;
}
void solve(){
cin >> m >> n;
for(int i=1;i<=m;i++){
cin >> k[i] >> s[i] >> t[i];
p.push_back({s[i],i});
p.push_back({t[i]+1,-i});
}
sort(p.begin(),p.end());
int l=1,r=inf,res=inf;
while(r>=l){
int mid=(l+r)>>1;
if(check(mid)) res=mid,r=mid-1;
else l=mid+1;
}
cout << res << '\n';
}
signed main(){
freopen("schedule.inp","r",stdin);
freopen("schedule.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int test=1;//cin >> test;
while(test--) solve();
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKbXQxOTkzN182NCBybmcoY2hyb25vOjpzdGVhZHlfY2xvY2s6Om5vdygpLnRpbWVfc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sKICAgICAgICBpbnQgY250PWluZjsKICAgICAgICBpZigoZC5maS1wcmUpPGluZi94KSBjbnQ9KGQuZmktcHJlKSp4OwogICAgICAgIHdoaWxlKGNudCAmJiAhcHEuZW1wdHkoKSl7CiAgICAgICAgICAgIGludCBpZD1wcS50b3AoKS5zZTsKICAgICAgICAgICAgaW50IG51bT1taW4oY3VyW2lkXSxjbnQpOwogICAgICAgICAgICBjbnQtPW51bTtjdXJbaWRdLT1udW07CiAgICAgICAgICAgIGlmKGN1cltpZF09PTApIHBxLnBvcCgpOwogICAgICAgIH0KICAgICAgICBwcmU9ZC5maTsKICAgICAgICBpZihkLnNlPDAgJiYgY3VyWy1kLnNlXSE9MCkgcmV0dXJuIGZhbHNlOwogICAgICAgIGVsc2UgaWYoZC5zZT4wKSBwcS5wdXNoKHt0W2Quc2VdLGQuc2V9KTsKICAgIH0KICAgIHJldHVybiB0cnVlOwp9Cgp2b2lkIHNvbHZlKCl7CiAgICBjaW4gPj4gbSA+PiBuOwogICAgZm9yKGludCBpPTE7aTw9bTtpKyspewogICAgICAgIGNpbiA+PiBrW2ldID4+IHNbaV0gPj4gdFtpXTsKICAgICAgICBwLnB1c2hfYmFjayh7c1tpXSxpfSk7CiAgICAgICAgcC5wdXNoX2JhY2soe3RbaV0rMSwtaX0pOwogICAgfQogICAgc29ydChwLmJlZ2luKCkscC5lbmQoKSk7CiAgICBpbnQgbD0xLHI9aW5mLHJlcz1pbmY7CiAgICB3aGlsZShyPj1sKXsKICAgICAgICBpbnQgbWlkPShsK3IpPj4xOwogICAgICAgIGlmKGNoZWNrKG1pZCkpIHJlcz1taWQscj1taWQtMTsKICAgICAgICBlbHNlIGw9bWlkKzE7CiAgICB9CiAgICBjb3V0IDw8IHJlcyA8PCAnXG4nOwp9CgpzaWduZWQgbWFpbigpewogICAgZnJlb3Blbigic2NoZWR1bGUuaW5wIiwiciIsc3RkaW4pOwogICAgZnJlb3Blbigic2NoZWR1bGUub3V0IiwidyIsc3Rkb3V0KT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