結果

問題 No.2623 Room Allocation
ユーザー poeMoon
提出日時 2024-02-11 15:27:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 404 ms / 2,000 ms
コード長 551 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 82,096 KB
実行使用メモリ 125,336 KB
最終ジャッジ日時 2024-09-28 17:31:36
合計ジャッジ時間 5,995 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

N, X, Y = map(int, input().split())
r = X + Y
g = [[0, 0] for _ in range(r)]
m = ["A", "B"]
for i in range(N):
    P, c = input().split()
    P = int(P)
    g[i % r][m.index(c)] += P
g.sort(key=lambda gi: -abs(gi[0] - gi[1]))
ans = 0
for i in range(r):
    A, B = g[i][0], g[i][1]
    if A >= B:
        if X > 0:
            X -= 1
            ans += A
        else:
            Y -= 1
            ans += B
    else:
        if Y > 0:
            Y -= 1
            ans += B
        else:
            X -= 1
            ans += A
print(ans)
#print(*g)
0