結果

問題 No.2623 Room Allocation
ユーザー miya145592
提出日時 2024-02-10 00:44:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 800 ms / 2,000 ms
コード長 528 bytes
コンパイル時間 130 ms
コンパイル使用メモリ 82,568 KB
実行使用メモリ 210,768 KB
最終ジャッジ日時 2024-09-28 16:47:44
合計ジャッジ時間 7,118 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N, X, Y = map(int, input().split())
PC = [input().split() for _ in range(N)]
S = X+Y
dp = [[0 for _ in range(2)] for _ in range(S)]
for i, pc in enumerate(PC):
    p, c = pc
    p=int(p)
    if c=="A":
        dp[i%S][0]+=p
    else:
        dp[i%S][1]+=p
for i in range(S):
    a, b = dp[i]
    dp[i] = [a, b, a-b, i]
dp.sort(key=lambda x:(x[2], x[0]))
ans = 0
for _ in range(X):
    a, b, sa, i = dp.pop()
    ans += a
for _ in range(Y):
    a, b, sa, i = dp.pop()
    ans += b
print(ans)
0