結果

問題 No.297 カードの数式
ユーザー rlangevinrlangevin
提出日時 2024-01-18 00:26:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 41 ms / 1,000 ms
コード長 711 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 53,460 KB
最終ジャッジ日時 2024-01-18 00:26:13
合計ジャッジ時間 2,529 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 39 ms
53,460 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 AC 39 ms
53,460 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 38 ms
53,460 KB
testcase_06 AC 38 ms
53,460 KB
testcase_07 AC 38 ms
53,460 KB
testcase_08 AC 38 ms
53,460 KB
testcase_09 AC 38 ms
53,460 KB
testcase_10 AC 38 ms
53,460 KB
testcase_11 AC 38 ms
53,460 KB
testcase_12 AC 38 ms
53,460 KB
testcase_13 AC 38 ms
53,460 KB
testcase_14 AC 38 ms
53,460 KB
testcase_15 AC 38 ms
53,460 KB
testcase_16 AC 39 ms
53,460 KB
testcase_17 AC 39 ms
53,460 KB
testcase_18 AC 38 ms
53,460 KB
testcase_19 AC 40 ms
53,460 KB
testcase_20 AC 39 ms
53,460 KB
testcase_21 AC 39 ms
53,460 KB
testcase_22 AC 39 ms
53,460 KB
testcase_23 AC 39 ms
53,460 KB
testcase_24 AC 41 ms
53,460 KB
testcase_25 AC 39 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import *

N = int(input())
C = list(input().split())
A = []
p, m = 0, 0
for c in C:
    if c == "+":
        p += 1
    elif c == "-":
        m += 1
    else:
        A.append(int(c))

B = deepcopy(A)
ma = 0
A.sort(reverse=True)
for i in range(m):
    ma -= A.pop()
for i in range(p):
    ma += A.pop()
v = ""
for a in A:
    v += str(a)
ma += int(v)

mi = 0
B.sort(reverse=True)
if m:
    p += 1
    for i in range(p):
        mi += B.pop()
    for i in range(m-1):
        mi -= B.pop()
    v = ""
    for b in B:
        v += str(b)
    mi -= int(v)
else:
    S = [""] * (p + 1)
    for i in range(len(B)):
        S[i%(p+1)] += str(B[-1-i])
    for s in S:
        mi += int(s)
    
print(ma, mi)
0