結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー keijakkeijak
提出日時 2020-10-09 23:55:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,067 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 10,940 KB
実行使用メモリ 48,972 KB
最終ジャッジ日時 2023-09-27 20:15:00
合計ジャッジ時間 21,397 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
8,048 KB
testcase_01 AC 14 ms
8,132 KB
testcase_02 AC 14 ms
8,220 KB
testcase_03 AC 15 ms
8,072 KB
testcase_04 AC 14 ms
8,052 KB
testcase_05 AC 15 ms
8,024 KB
testcase_06 AC 16 ms
8,184 KB
testcase_07 AC 16 ms
8,044 KB
testcase_08 AC 16 ms
8,004 KB
testcase_09 AC 15 ms
8,084 KB
testcase_10 AC 15 ms
8,080 KB
testcase_11 AC 15 ms
8,132 KB
testcase_12 AC 14 ms
8,044 KB
testcase_13 AC 14 ms
7,944 KB
testcase_14 AC 14 ms
8,004 KB
testcase_15 AC 15 ms
8,076 KB
testcase_16 AC 14 ms
8,044 KB
testcase_17 AC 15 ms
8,072 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 42 ms
11,612 KB
testcase_22 WA -
testcase_23 AC 32 ms
10,768 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 75 ms
16,360 KB
testcase_27 AC 32 ms
10,944 KB
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
7,944 KB
testcase_44 AC 14 ms
8,048 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 = dict()
    for i in range(n):
        if A[i] not in P:
            P[A[i]] = B[i]
        else:
            P[A[i]] += B[i]
    P = [(k, v) for k, v in P.items()]
    P.sort()
    n = len(P)

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

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

    mp = n
    for i in range(n):
        if cum[i + 1] > cum[n] - cum[i + 1]:
            mp = i
            break

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

    if mp == n:
        y = max([y for y,z in P])
        return y, int(f(y) + 0.5)

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


print(*solve())
0