結果

問題 No.1906 Twinkle Town
ユーザー siganai
提出日時 2022-04-15 22:15:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 761 bytes
コンパイル時間 533 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 108,176 KB
最終ジャッジ日時 2024-12-25 00:57:54
合計ジャッジ時間 10,831 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other WA * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env PyPy3

from collections import Counter, defaultdict, deque
import itertools
import re
import math
from functools import reduce
import operator
import bisect
import heapq
import functools
mod=10**9+7

import sys
input=sys.stdin.readline
t = int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    a.sort()
    ans = 0
    l=0
    r=n-1
    cnt = 0
    while cnt < n:
        if cnt % 2 == 0:
            if cnt == n - 1:
                ans += a[l]
                cnt += 1
                continue
            if a[r] - a[r-1] + a[l] >= a[l+1]:
                ans += a[r] - a[r-1]
                r -= 1
            else:
                l += 1
        else:
            r -= 1
        cnt += 1
    print(ans)
0