#include #include #include #define MAX_P 15010 #define INF (long long)1e13 int main(){ std::cout<>N>>P; for(int j = 0; j < P; j++)dp[0][j]=dp[1][j]=INF; dp[1][0] = 0; for(int i = 0; i < N; i++){ std::cin>>a>>b>>c; for(int j = 0; j <= P; j++){ if(dp[(i+1)%2][j] == INF) continue; dp[i%2][j] = std::min(dp[(i+1)%2][j]+a,dp[i%2][j] ); dp[i%2][j+1] = std::min(dp[(i+1)%2][j]+b,dp[i%2][j+1]); dp[i%2][j+2] = std::min(dp[(i+1)%2][j]+c,dp[i%2][j+2]); dp[i%2][j+3] = std::min(dp[(i+1)%2][j]+1,dp[i%2][j+3]); dp[(i+1)%2][j] = INF; } // for(int j = 0; j <= P; j++)std::cout<