結果

問題 No.1374 Absolute Game
ユーザー buey_tbuey_t
提出日時 2023-04-25 18:45:03
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 1,356 bytes
コンパイル時間 1,816 ms
コンパイル使用メモリ 87,164 KB
実行使用メモリ 99,372 KB
最終ジャッジ日時 2023-08-09 08:24:22
合計ジャッジ時間 10,513 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 223 ms
83,516 KB
testcase_01 AC 221 ms
83,436 KB
testcase_02 AC 227 ms
83,500 KB
testcase_03 AC 223 ms
83,532 KB
testcase_04 AC 215 ms
83,288 KB
testcase_05 AC 212 ms
83,288 KB
testcase_06 AC 218 ms
83,288 KB
testcase_07 AC 215 ms
83,008 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import *
from heapq import *
from bisect import *
from copy import *
from random import *
from collections import *
from itertools import *
from decimal import *
#tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
from functools import *
#@lru_cache(maxsize=None)
from operator import *
from sys import *
input = stdin.readline
# .rstrip()
INF = 10**18
mod1 = 10**9+7
mod2 = 998244353

#DecimalならPython
#再帰ならPython!!!!!!!!!!!!!!!!!!!!!!!!!!


'''
負を目指すか正を目指すかという話ではないのか
4通りあるか

'''

N = int(input())
C = list(map(int, input().split()))

ans = -INF

# 正-正
a = 0
b = 0
C.sort(reverse=True)
for i in range(N):
    if i%2 == 0:
        a += C[i]
    else:
        b += C[i]

ans = max(ans,abs(a)-abs(b))

# 正-負
a = 0
b = 0
C.sort(reverse=True)
i = 0
j = N-1
while i <= j:
    a += C[i]
    
    if i == j:
        break
    
    b += C[j]
    
    i += 1
    j -= 1

ans = max(ans,abs(a)-abs(b))

# 負-正
a = 0
b = 0
C.sort(reverse=True)
i = N-1
j = 0
while j <= i:
    a += C[i]
    
    if i == j:
        break
    
    b += C[j]
    
    i -= 1
    j += 1

ans = max(ans,abs(a)-abs(b))

# 正-正
a = 0
b = 0
C.sort()
for i in range(N):
    if i%2 == 0:
        a += C[i]
    else:
        b += C[i]

ans = max(ans,abs(a)-abs(b))

print(ans)













0