#include #define int long long using namespace std; const int N=100010; int xx[N],a[N],b[N]; int n,m,ans=LLONG_MAX; bool P(int x,int y) { int cur=0,cnt2=0; for(int i=1;i<=n;++i){ cur=xx[i]; cur+=(a[i]>=x); cur+=(b[i]>=y); cnt2+=(cur>=2); } return cnt2>=m; } int sc(int x,int y){ int ress=0,now=0; for(int i=1;i<=n;++i) { now=xx[i]; now+=(a[i]>=x); now+=(b[i]>=y); ress+=(now>=3); }return ress; }signed main(){ cin>>n>>m; int mxa=-1,mxb=-1; for(int i=1;i<=n;++i){ cin>>xx[i]>>a[i]>>b[i]; mxa=max(mxa,a[i]);mxb=max(mxb,b[i]); }int l1,r1=mxa+1; while(l1<=r1){ int mid1=l1+(l1+r1)/2; int l=0,r=mxb+1,res=-1; while(l<=r){ int mid=l+(r-l)/2; if(P(mid1,mid)){ res=mid; l=mid+1; }else r=mid-1; }if(sc(mid1,res)