#pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #pragma GCC target ("avx2") #include #include #include #include #include #include #include #include #include #include #include #include #include struct xorshift64 { unsigned long long int x = 88172645463325252ULL; inline unsigned short nextUShort() { x = x ^ (x << 7); return x = x ^ (x >> 9); } inline unsigned int nextUShortMod(unsigned long long int mod) { x = x ^ (x << 7); x = x ^ (x >> 9); return ((x & 0x0000ffffffffffff) * mod) >> 48; } inline unsigned int nextUInt() { x = x ^ (x << 7); return x = x ^ (x >> 9); } inline unsigned int nextUIntMod(unsigned long long int mod) { x = x ^ (x << 7); x = x ^ (x >> 9); return ((x & 0x00000000ffffffff) * mod) >> 32; } inline unsigned long long int nextULL() { x = x ^ (x << 7); return x = x ^ (x >> 9); } inline double nextDouble() { x = x ^ (x << 7); x = x ^ (x >> 9); return (double)x * 5.42101086242752217e-20; } }; struct timer { double t = 0.0; double lastStop = 0.0; bool stopped = false; timer() { restart(); } inline void restart() { t = now(); stopped = false; } inline void start() { if (stopped) { t += now() - lastStop; stopped = false; } } inline void stop() { if (!stopped) { lastStop = now(); stopped = true; } } inline double time() { if (stopped) return lastStop - t; else return now() - t; } inline double now() { unsigned long long l, h; __asm__ ("rdtsc" : "=a"(l), "=d"(h)); #ifdef LOCAL return (double)(l | h << 32) * 2.857142857142857e-10; // 1 / 3.5e9, for local (Ryzen 9 3950X) #else // return (double)(l | h << 32) * 3.5714285714285715e-10; // 1 / 2.8e9, for AWS EC2 C3 (Xeon E5-2680 v2) // return (double)(l | h << 32) * 3.4482758620689656e-10; // 1 / 2.9e9, for AWS EC2 C4 (Xeon E5-2666 v3) // return (double)(l | h << 32) * 3.333333333333333e-10; // 1 / 3.0e9, for AWS EC2 C5 (Xeon Platinum 8124M / Xeon Platinum 8275CL) return (double)(l | h << 32) * 4.3478260869565215e-10; // 1 / 2.3e9, for yukicoder judge #endif } }; using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef pair Pii; const ll mod = 1000000007; timer theTimer; xorshift64 theRandom; mt19937 theMersenne(1); // hyper parameters // enums // structs // constants constexpr int n = 50; constexpr int k = 50; // inputs array t, u; // outputs array b, m, e; // internals void receive_input() { int _n, _k; cin >> _n >> _k; for (int i = 0; i < k; i++) cin >> t[i]; for (int i = 0; i < k; i++) cin >> u[i]; } void init() { } inline ll calc_pendulum_pos(ll bm, ll time) { ll in_cycle_time = time % (bm * 4); if (in_cycle_time <= bm) return in_cycle_time; else if (in_cycle_time <= bm * 3) return bm * 2 - in_cycle_time; else return in_cycle_time - bm * 4; } void solve() { ll best_score = 0; ll best_bm1 = -1; ll best_bm2 = -1; for (int bm1 = 1; bm1 * 3 < min(t[0], u[0]); bm1++) { ll t_score = 0; ll u_score = 0; for (int i = 0; i < k; i++) { ll pos1 = calc_pendulum_pos(bm1, t[i]); ll pos2 = -pos1; t_score += (ll)(1e7 * (double) abs(pos1 - pos2) / (double) (bm1 * 3)); } for (int i = 0; i < k; i++) { ll pos1 = calc_pendulum_pos(bm1, u[i]); ll pos2 = -pos1; u_score += (ll)(1e7 / (sqrt(abs(pos1 - pos2) / 20.0 + 1.0))); } ll total_score = (t_score / k) * (u_score / k); if (total_score > best_score) { best_score = total_score; best_bm1 = bm1; best_bm2 = -1; } } for (ll bm1 = 1; ; bm1++) { for (ll bm2 = 1; bm2 <= bm1; bm2++) { ll t_score = 0; ll u_score = 0; for (int i = 0; i < k; i++) { ll pos1 = calc_pendulum_pos(bm1, t[i]); ll pos2 = calc_pendulum_pos(bm2, t[i]); t_score += (ll)(1e7 * (double) abs(pos1 - pos2) / (double) (bm1 + bm2)); } for (int i = 0; i < k; i++) { ll pos1 = calc_pendulum_pos(bm1, u[i]); ll pos2 = calc_pendulum_pos(bm2, u[i]); u_score += (ll)(1e7 / (sqrt(abs(pos1 - pos2) / 20.0 + 1.0))); } ll total_score = (t_score / k) * (u_score / k); if (total_score > best_score) { best_score = total_score; best_bm1 = bm1; best_bm2 = bm2; } } if (theTimer.time() > 1.900) break; } cerr << "score = " << best_score << endl; if (best_bm2 == -1) { for (int i = 0; i < n / 2; i++) { b[i] = best_bm1 * 2; m[i] = best_bm1; e[i] = best_bm1; } for (int i = n / 2; i < n; i++) { b[i] = best_bm1; m[i] = best_bm1; e[i] = 1; } } else { for (int i = 0; i < n / 2; i++) { b[i] = best_bm1; m[i] = best_bm1; e[i] = 1; } for (int i = n / 2; i < n; i++) { b[i] = best_bm2; m[i] = best_bm2; e[i] = 1; } } } void output_ans() { for (int i = 0; i < n; i++) cout << b[i] << " " << m[i] << " " << e[i] << endl; } int main(int argc, char *argv[]) { cin.tie(0); ios::sync_with_stdio(false); receive_input(); init(); solve(); output_ans(); return 0; }