結果

問題 No.2501 Maximum Inversion Number
ユーザー suisen
提出日時 2023-07-24 20:27:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,551 ms / 2,000 ms
コード長 1,068 bytes
コンパイル時間 560 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 137,432 KB
最終ジャッジ日時 2024-09-15 13:56:04
合計ジャッジ時間 8,491 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import sys
from typing import List
def main(_: int, m: int, l: List[int], r: List[int]):
if not (sum(l) <= m <= sum(r)):
return -1
if m == sum(l):
return (m * m - sum(e * e for e in l)) // 2
tl, tr = 0, 10 ** 9 + 10
while abs(tr - tl) > 1:
t = (tl + tr) // 2
if sum(max(a, min(t, b)) for a, b in zip(l, r)) < m:
tl = t
else:
tr = t
t0, d = tl, m - sum(max(a, min(tl, b)) for a, b in zip(l, r))
x = 0
for a, b in zip(l, r):
c = max(a, min(t0, b))
if d > 0 and a <= t0 < b:
c += 1
d -= 1
x += c * c
return (m * m - x) // 2
if __name__ == '__main__':
t = int(sys.stdin.readline().rstrip())
answers = []
for _ in range(t):
n, m = map(int, sys.stdin.readline().rstrip().split())
l = list(map(int, sys.stdin.readline().rstrip().split()))
r = list(map(int, sys.stdin.readline().rstrip().split()))
answers.append(main(n, m, l, r))
print('\n'.join(map(str, answers)))
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0