結果

問題 No.3130 Twin's Add Max Min Game
ユーザー 👑 loop0919
提出日時 2025-02-17 01:38:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 576 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 82,592 KB
実行使用メモリ 117,536 KB
最終ジャッジ日時 2025-02-17 03:03:09
合計ジャッジ時間 10,865 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter

N = int(input())
A = sorted(map(int, input().split()))
S = Counter(input().split())

if S["add"] == N:
    print(sum(A))
    exit()
elif S["max"] == N:
    print(max(A))
    exit()
elif S["min"] == N:
    print(0)
    exit()

ans = A[N - S["min"] - 1]
A.pop(N - S["min"] - 1)

if S["add"] > 0:
    S["add"] -= 1
else:
    S["max"] -= 1

for a in A:
    if S["add"] > 0:
        ans += a
        S["add"] -= 1
    elif S["max"] > 0:
        ans = max(ans, a)
        S["max"] -= 1
    else:
        ans = min(ans, a)
        break

print(ans)

0