結果
| 問題 |
No.2835 Take and Flip
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-09 21:25:45 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 244 ms / 2,000 ms |
| コード長 | 940 bytes |
| コンパイル時間 | 215 ms |
| コンパイル使用メモリ | 82,440 KB |
| 実行使用メモリ | 139,880 KB |
| 最終ジャッジ日時 | 2024-08-09 21:26:10 |
| 合計ジャッジ時間 | 6,389 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
#input = sys.stdin.readline
n = int(input())
alist = list(map(int,input().split()))
#alist = []
#s = input()
#n,m = map(int,input().split())
#for i in range(n):
# alist.append(list(map(int,input().split())))
x = 0
y = 0
t = 0
a = []
b = []
for i in alist:
if i > 0:
a.append(i)
elif i < 0:
b.append(-i)
a.sort()
b.sort()
a = collections.deque(a)
b = collections.deque(b)
for i in range(n):
if len(a) >= 1 and len(b) >= 1:
if t == 0:
x += a.pop()
else:
y += b.pop()
elif a:
if t == 0:
x += a.pop()
else:
y -= a.popleft()
elif b:
if t == 0:
x -= b.popleft()
else:
y += b.pop()
else:
break
t ^= 1
print(x-y)