#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using ull = unsigned long long; const int INF = 1e9; const ll MOD = 1e9 + 7; #define REP(i, n) for(ll i = 0; i < n; i++) int main() { int n, p; cin >> n >> p; vector a(n), b(n), c(n); REP(i, n){ cin >> a[i] >> b[i] >> c[i]; } vector> dp(n, vector(p + 4, INF)); dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0]; dp[0][3] = 1; for(ll i = 0; i < n - 1; i++){ for(ll j = 0; j <= p; j++){ if(j <= p - 3){ dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + a[i + 1]); dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + b[i + 1]); dp[i + 1][j + 2] = min(dp[i + 1][j + 2], dp[i][j] + c[i + 1]); dp[i + 1][j + 3] = min(dp[i + 1][j + 3], dp[i][j] + 1); } else if(j == p - 2){ dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + a[i + 1]); dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + b[i + 1]); dp[i + 1][j + 2] = min(dp[i + 1][j + 2], dp[i][j] + c[i + 1]); } else if(j == p - 1){ dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + a[i + 1]); dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + b[i + 1]); } else{ dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + a[i + 1]); } } } printf("%.7lf\n", (double)dp[n - 1][p] / (double)n); }