結果

問題 No.1279 Array Battle
コンテスト
ユーザー cologne
提出日時 2025-12-18 17:25:10
言語 PyPy3
(7.3.17)
結果
AC  
実行時間 641 ms / 2,000 ms
コード長 1,217 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 348 ms
コンパイル使用メモリ 82,604 KB
実行使用メモリ 82,132 KB
最終ジャッジ日時 2025-12-18 17:25:17
合計ジャッジ時間 5,323 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
from typing import List, Tuple


def int1(x: str, /): return int(x) - 1


def input(): return sys.stdin.readline().rstrip('\n')


def dbg(*args, **kwargs):
    print(*(repr(arg) for arg in args), *(f'{k}: {repr(v)}' for k, v in kwargs.items()), sep='; ', file=sys.stderr)


def next_permutation(a):
    for i in range(len(a) - 2, -1, -1):
        if a[i] < a[i + 1]:
            break
    else:
        return False

    j = next(j for j in reversed(range(i + 1, len(a))) if a[i] < a[j])
    a[i], a[j] = a[j], a[i]
    a[i + 1:] = reversed(a[i + 1:])
    return True


def main():
    n = int(input())
    *a, = map(int, input().split())
    a = sorted((v, i) for i, v in enumerate(a))
    *b, = map(int, input().split())
    mx = 0
    cn = 0
    while True:
        r = sum(max(p - q, 0) for (p, _), q in zip(a, b))
        if mx < r:
            mx = r
            cn = 0
        if mx == r:
            cn += 1

        if not next_permutation(a):
            break
    return cn


def _start():
    ret = main()

    if ret is not None:
        if isinstance(ret, List) or isinstance(ret, Tuple):
            print(*ret)
        else:
            print(ret)


if __name__ == '__main__':
    _start()
0