def f(t, B, M, E): u, v = divmod(B-M, E) a = time0(u, B, E) # print(a) if t < a: min1 = 0 max1 = u+1 while max1 - min1 > 1: h = (max1 + min1) // 2 ha = time0(h-1, B, E) if ha > t: max1 = h else: min1 = h hmin = time0(min1-1, B, E) hmax = time0(min1, B, E) # print(min1, hmin, hmax) px = min(abs(t - hmin), abs(hmax - t)) if min1 % 2 == 0: return px else: return -px else: p, q = divmod(t - a, 2*M) px = min(abs(t - (a + p*2*M)), abs(t - (a + (p+1)*2*M))) if (p + u + 1) % 2 == 0: return px else: return -px def time0(times, B, E): return (times + 1) * (2 * B - times * E) def score(B, M, E): Sconf = 0 for u in T: a = 0 x = [0] * N for i in range(N): x[i] = f(u, B[i], M[i], E[i]) for i in range(N-1): for j in range(i+1, N): a += abs(x[i] - x[j]) / (B[i] + B[j]) # print(x, a) Sconf += round(2 * 10 ** 7 * a / (N * (N - 1))) Sconf = round(Sconf / K) Scoop = 0 for u in U: for i in range(N): x[i] = f(u, B[i], M[i], E[i]) Scoop += 10 ** 7 / (((max(x) - min(x)) / 20 + 1) ** 0.5) Scoop = round(Scoop / K) # print(Sconf, Scoop) return Sconf * Scoop def stdinput(): N, K = map(int, input().split()) T = list(map(int, input().split())) U = list(map(int, input().split())) return N, K, T, U def randinput(): N = 50 K = 50 delta = 200 G = [0] * (2 * K + 1) i = random.randint(0, 1) F = [0] * (2 * K) while True: for i in range(2 * K): F[i] = random.random() if F[i] == 0: F[i] = random.random() for i in range(2*K): G[i+1] = round(G[i] + delta / F[i]) if G[-1] <= 10 ** 9: break if i % 2 == 0: T = G[1::2] U = G[2::2] else: T = G[2::2] U = G[1::2] return N, K, T, U import random import time # N, K, T, U = randinput() N, K, T, U = stdinput() ut = time.time() NB = [0] * N NM = [0] * N NE = [0] * N maxscore = 0 m = 3 # i = 0 while time.time() - ut < 1.8: # i += 1 for i in range(N): NB[i] = random.randint(1, m) NM[i] = random.randint(1, NB[i]) NE[i] = random.randint(1, m) sc = score(NB, NM, NE) if maxscore < sc: B = list(NB) M = list(NM) E = list(NE) maxscore = sc # for i in range(N): # print(f(m, B[i], M[i], E[i])) for i in range(N): print(B[i], M[i], E[i]) # print(i)