結果
| 問題 | No.297 カードの数式 | 
| コンテスト | |
| ユーザー |  taba | 
| 提出日時 | 2016-04-15 03:30:32 | 
| 言語 | Python2 (2.7.18) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 13 ms / 1,000 ms | 
| コード長 | 567 bytes | 
| コンパイル時間 | 54 ms | 
| コンパイル使用メモリ | 6,912 KB | 
| 実行使用メモリ | 6,400 KB | 
| 最終ジャッジ日時 | 2024-12-26 02:29:27 | 
| 合計ジャッジ時間 | 1,192 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 23 | 
ソースコード
n=input()
c=raw_input().split()
a=sorted([i for i in c if i.isdigit()])
p,m=c.count("+"),c.count("-")
#print a,p,m
#big
b=a[p+m:][::-1]
c=a[:p+m]
for i in range(m):
	b+=["-",c.pop(0)]
for i in range(p):
	b+=["+",c.pop()]
big=eval("".join(b))
#print b
#small
if m>0:
	b=[a[0]]
	c=a[1:]
	for i in range(p):
		b+=["+",c.pop(0)]
	for i in range(m-1):
		b+=["-",c.pop(0)]
	#print b,c
	if len(c)>0:
		b+=["-"]+c[::-1]
	small=eval("".join(b))
else:
	b=[""for i in range(p+1)]
	for i in range(len(a)):
		b[i%(p+1)]+=a[i]
	#print b
	small=sum(int(i)for i in b)
print big,small
            
            
            
        