#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define mt make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; int r[5010][4]; int main(){ ios::sync_with_stdio(false); cin.tie(0); int N, P; cin >> N >> P; rep(i, N)rep(j, 3)cin >> r[i][j]; rep(i, N)r[i][3] = 1; ll INF = LLONG_MAX / 4; vll cu(P + 1, INF), ne(P + 1, INF); cu[0] = 0; rep(i, N) { fill(all(ne), INF); ll x; for(int j = 0; j <= P; ++j)if((x = cu[j])