#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } const int MX = 60; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, k; cin >> n >> k; vector p(n), S(n), T(n); for(int i = 0; i < n; i++) cin >> p[i] >> S[i] >> T[i]; int s_sum = accumulate(S.begin(), S.end(), 0); int t_sum = accumulate(T.begin(), T.end(), 0); if(t_sum > MX){ cout << -1 << endl; return 0; } if(s_sum <= MX){ cout << 1 << ' ' << 1 << ' ' << 1 << endl; return 0; } vector prod(n); for(int i = 0; i < n; i++){ prod[i] = 1; for(int j = i+1; j < n; j++){ prod[i] *= p[j]; } } auto to_int = [&](vector &v){ int ans = 0; for(int i = 0; i < n; i++){ ans += prod[i]*v[i]; } return ans; }; auto to_vec = [&](int s){ vector ans(n); for(int i = 0; i < n; i++){ ans[i] = s/prod[i]; s %= prod[i]; } return ans; }; vector x = {2, 1}; auto v = vector(n); for(int i = 0; i < n; i++) v[i] = p[i]-1; int s_max = to_int(v); int goal = s_max+1; vector mn(s_max+2, 1e9); vector mx(s_max+2, 0); vector pr(s_max+2); vector e(s_max+2); vector ok(s_max+2); ok[s_max] = true; mn[s_max] = 1; mx[s_max] = 1; pr[s_max] = 1; e[s_max] = 1; for(int s = 0; s <= s_max; s++){ auto v = to_vec(s); } for(int s = s_max; s >= 0; s--){ if(!ok[s]) continue; // debug_value(s) auto v = to_vec(s); // print_vector(v); // int mask = 0; // for(int i = 0; i < n; i++){ // if(v[i] > 0) mask += 1< mask) continue; double proba = 1.0; for(int i = 0; i < n; i++){ int already = p[i]-v[i]; int already_and_ok = already > k ? already-k : 0; int ok = already_and_ok+v[i]; if(t&(1<