結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー keijakkeijak
提出日時 2020-10-09 23:25:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 897 bytes
コンパイル時間 134 ms
コンパイル使用メモリ 11,080 KB
実行使用メモリ 51,628 KB
最終ジャッジ日時 2023-09-27 19:49:52
合計ジャッジ時間 19,902 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,232 KB
testcase_01 AC 14 ms
8,296 KB
testcase_02 AC 13 ms
8,340 KB
testcase_03 WA -
testcase_04 AC 14 ms
8,212 KB
testcase_05 AC 13 ms
8,292 KB
testcase_06 AC 15 ms
8,204 KB
testcase_07 WA -
testcase_08 AC 15 ms
7,928 KB
testcase_09 AC 15 ms
8,216 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 14 ms
8,232 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 14 ms
8,316 KB
testcase_17 AC 15 ms
8,300 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 38 ms
11,284 KB
testcase_22 WA -
testcase_23 AC 30 ms
10,488 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 14 ms
8,264 KB
testcase_44 AC 13 ms
8,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    n = ini()
    A = inl()
    B = inl()

    P = []
    for i in range(n):
        P.append((A[i], B[i]))
    P.sort()

    if n == 1:
        return A[0], 0

    cum = [None] * (n + 1)
    cum[0] = 0
    for i in range(n):
        cum[i + 1] = cum[i] + P[i][1]

    mindiff = 10 ** 8
    mp = 0
    for i in range(n):
        d = abs(cum[n] - 2 * cum[i])
        if mindiff > d:
            mindiff = d
            mp = i

    def f(x):
        res = 0
        for i in range(n):
            res += B[i] * abs(x - A[i])
        return res

    return P[mp][0], int(f(P[mp][0]) + 0.5)


print(*solve())
0