#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define int ll
using namespace std;
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int mod=1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int mul(int a,int b)
{
return ((a)*1ll*(b))%mod;
}
void add(int &a,int b)
{
a+=b;
if(a>=mod)a-=mod;
}
int sub(int a,int b){
a-=b;
if(a<0){
a+=mod;
}
return a;
}
int powz(int a,int b)
{
int res=1;
while(b)
{
if(b&1)res=mul(res,a);
b/=2;
a=mul(a,a);
}
return res;
}
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
input>>x.F>>x.S;
return input;
}
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
for(auto& i:x)
input>>i;
return input;
}
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
for(auto& i:x)
output<<i<<' ';
return output;
}
const int N=500002;
vector<pair<int,ll>>rev[N];
int lazy[10*N];
pair<int,int> t[10*N];
void push(int v) {
t[v*2].F += lazy[v];
lazy[v*2] += lazy[v];
t[v*2+1].F += lazy[v];
lazy[v*2+1] += lazy[v];
lazy[v] = 0;
}
pair<int,int>merge(pi a,pi b){
if(a.F>b.F){
return a;
}
if(b.F>a.F){
return b;
}
return b;
}
void update(int v, int tl, int tr, int l, int r, int addend) {
if (l > r)
return;
if(l==r&&tl==l&&tr==r){
t[v].F+=addend;
lazy[v]+=addend;
return;
}
if (l == tl && tr == r) {
t[v].F += addend;
lazy[v] += addend;
} else {
push(v);
int tm = (tl + tr) / 2;
update(v*2, tl, tm, l, min(r, tm), addend);
update(v*2+1, tm+1, tr, max(l, tm+1), r, addend);
t[v] = merge(t[v*2], t[v*2+1]);
}
}
pi query(int v, int tl, int tr, int l, int r) {
if (l > r)
return {-1e18,0};
if (l <= tl && tr <= r)
return t[v];
push(v);
int tm = (tl + tr) / 2;
return merge(query(v*2, tl, tm, l, min(r, tm)),
query(v*2+1, tm+1, tr, max(l, tm+1), r));
}
void build(int v,int tl,int tr){
if(tl==tr){
t[v].S=tl;
return;
}
build(2*v,tl,(tl+tr)/2);
build(2*v+1,((tl+tr)/2)+1,tr);
}
void solve(){
int n;
ll k;
cin>>n>>k;
vector<pair<int,int>>abc;
for(int i=0;i<n;i++){
int l,r;
ll p;
cin>>l>>r>>p;
rev[r].pb({l,p});
abc.pb({l,r});
}
ll ans=0;
build(1,1,200000);
pair<int,int>opt;
for(int i=1;i<=200000;i++){
update(1,1,200000,1,i,-k);
if(rev[i].size()==0)continue;
sort(all(rev[i]));
for(int j=rev[i].size()-1;j>=0;j--){
update(1,1,200000,1,rev[i][j].F,rev[i][j].S);
}
pi zz=query(1,1,200000,1,i);
ll cost=zz.F,index=zz.S;
if(ans<cost){
ans=cost;
opt={index,i};
}
}
if(ans==0){
cout<<0;
return;
}
cout<<ans<<' '<<opt.F<<' '<<opt.S<<' ';
vector<int>anss;
for(int i=0;i<n;i++){
if(abc[i].F>=opt.F&&abc[i].F<=opt.S&&abc[i].S<=opt.S){
anss.pb(i+1);
}
}
cout<<anss.size()<<"\n";
cout<<anss;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int tc=1;
//~ cin>>tc;
for(int _=0;_<tc;_++){
//~ cout<<"Case #"<<_+1<<": ";
solve();
if(_!=tc-1)
cout<<"\n";
}
}
I3ByYWdtYSBHQ0MgdGFyZ2V0ICgiYXZ4MiIpCiNwcmFnbWEgR0NDIG9wdGltaXphdGlvbiAoIk8zIikKI3ByYWdtYSBHQ0Mgb3B0aW1pemF0aW9uICgidW5yb2xsLWxvb3BzIikKI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBpbnQgbGwKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIAojZGVmaW5lIGFsbChhKSBh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