結果
問題 |
No.972 選び方のスコア
|
ユーザー |
|
提出日時 | 2021-03-25 22:57:23 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 208 ms / 2,000 ms |
コード長 | 945 bytes |
コンパイル時間 | 524 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 120,320 KB |
最終ジャッジ日時 | 2024-11-27 08:31:48 |
合計ジャッジ時間 | 6,797 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
def binary_search_int(ok, ng, test): """ :param ok: solve(x) = True を必ず満たす点 :param ng: solve(x) = False を必ず満たす点 """ while abs(ok - ng) > 1: mid = (ok + ng) // 2 if test(mid): ok = mid else: ng = mid return ok def example(): global input example = iter( """ 10 3 8 9 7 2 2 10 10 35 5 """ .strip().split("\n")) input = lambda: next(example) ############################################################## import sys input = sys.stdin.readline # example() def test(x): if x==0: return True return A[i-x]+A[N-x]-2*m>0 N=int(input()) A=list(map(int, input().split())) A.sort() acc=[0] for a in A: acc.append(acc[-1]+a) res=0 for i in range(N): m=A[i] k=binary_search_int(0,min(i+1,N-i),test) S=acc[i+1]-acc[i-k] +acc[N]-acc[N-k] -m*(2*k+1) if res<S: res=S print(res)