結果

問題 No.1906 Twinkle Town
ユーザー shotoyoo
提出日時 2022-04-15 23:07:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,034 bytes
コンパイル時間 411 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 118,644 KB
最終ジャッジ日時 2024-12-25 02:14:14
合計ジャッジ時間 10,891 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other WA * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, random
input = lambda : sys.stdin.readline().rstrip()

write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x))
debug = lambda x: sys.stderr.write(x+"\n")
YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); inf=10**18
LI = lambda : list(map(int, input().split()))
def dlist(*l, fill=0):
    if len(l)==1:
        return [fill]*l[0]
    ll = l[1:]
    return [dlist(*ll, fill=fill) for _ in range(l[0])]
sys.setrecursionlimit(3*10**5+10)

t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    if n%2==0:
        ans = 0
        for i in range(0,n,2):
            ans += a[i+1] - a[i]
    else:
        d = [a[i+1]-a[i] for i in range(n-1)]
        d.insert(0, a[0])
        cum = [0,0]
        for i in range(n):
            cum.append(cum[-2]+d[i])
        cum.pop(0)
        ans = 0
        for i in range(n//2+1):
            val = a[i] + cum[n-i] - cum[i+1]
            ans = max(ans, val)
    print(ans)
#     break
0