結果

問題 No.297 カードの数式
ユーザー しらっ亭
提出日時 2015-11-07 13:41:27
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 717 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-09-13 13:54:08
合計ジャッジ時間 1,800 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    N = int(input())
    C = input().split()

    np = nm = 0
    I = []
    for c in C:
        if c == '+':
            np += 1
        elif c == '-':
            nm += 1
        else:
            I += c
    I.sort()

    J = []

    for i in range(np + nm):
        J.append(int(I[i]))

    J.append(int(''.join(I[np + nm:][::-1])))

    K = J[::-1]

    mi = ma = 0
    for i in range(np + 1):
        mi += J[i]
        ma += K[i]
    for i in range(np + 1, np + nm + 1):
        mi -= J[i]
        ma -= K[i]

    if nm == 0:
        mi = 0
        for i in range(np):
            mi += int(I[-i - 1])
        mi += int(''.join(I[:-np]))

    print(ma, mi)


if __name__ == '__main__':
    solve()
0