結果
問題 | No.2501 Maximum Inversion Number |
ユーザー | naesira |
提出日時 | 2023-10-13 23:01:51 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 734 bytes |
コンパイル時間 | 991 ms |
コンパイル使用メモリ | 87,028 KB |
実行使用メモリ | 117,616 KB |
最終ジャッジ日時 | 2023-10-13 23:02:04 |
合計ジャッジ時間 | 11,125 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 66 ms
71,252 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 465 ms
109,680 KB |
testcase_08 | WA | - |
testcase_09 | AC | 123 ms
93,628 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 521 ms
116,276 KB |
testcase_15 | WA | - |
testcase_16 | AC | 1,986 ms
82,296 KB |
ソースコード
def bis(ok, ng): def is_ok(md): ttl = sum(min(max(L[i], md), R[i]) for i in range(n)) return ttl <= m while abs(ok - ng) > 1: md = (ng + ok) // 2 if is_ok(md): ok = md else: ng = md return ok T = int(input()) for _ in range(T): n, m = map(int, input().split()) L = list(map(int, input().split())) R = list(map(int, input().split())) if m < sum(L) or sum(R) < m: print(-1) continue k = max(R) if sum(R) == m else bis(min(L), max(R)) cnt = sorted([min(max(L[i], k), R[i]), i] for i in range(n)) ttl = sum(cnt[i][0] for i in range(n)) i = 0 while ttl < m: cnt[i][0] += 1 ttl += 1 i += 1 ans = sum(cnt[i][0] * (m - cnt[i][0]) for i in range(n)) // 2 print(ans)