結果
問題 | No.2501 Maximum Inversion Number |
ユーザー | chineristAC |
提出日時 | 2023-10-13 21:35:13 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,097 bytes |
コンパイル時間 | 275 ms |
コンパイル使用メモリ | 87,100 KB |
実行使用メモリ | 140,740 KB |
最終ジャッジ日時 | 2023-10-13 21:35:22 |
合計ジャッジ時間 | 8,029 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 116 ms
73,620 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 174 ms
106,872 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 1,366 ms
101,668 KB |
ソースコード
import sys from itertools import permutations import heapq from collections import deque import random input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) def solve(n,m,L,R): if m < sum(L) or sum(R) < m: return -1 cnt = [L[i] for i in range(n)] rest = m - sum(cnt) def cond(k): check = 0 for i in range(n): if L[i] <= k: check += min(k,R[i]) - L[i] return check <= rest ok = min(L) ng = max(R) + 1 while ng-ok>1: mid = (ok+ng)//2 if cond(mid): ok = mid else: ng = mid for i in range(n): cnt[i] = max(ok,L[i]) rest = m - sum(cnt) idx = [i for i in range(n)] idx.sort(key=lambda i:cnt[i]) for i in range(rest): cnt[i] += 1 res = m * (m-1)//2 for i in range(n): res -= cnt[i] * (cnt[i]-1) //2 return res for _ in range(int(input())): n,m = mi() L = li() R = li() print(solve(n,m,L,R))