結果

問題 No.2623 Room Allocation
ユーザー flygonflygon
提出日時 2024-02-09 21:48:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 305 ms / 2,000 ms
コード長 1,130 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 150,128 KB
最終ジャッジ日時 2024-02-09 21:48:47
合計ジャッジ時間 5,658 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,596 KB
testcase_01 AC 43 ms
55,596 KB
testcase_02 AC 42 ms
55,596 KB
testcase_03 AC 39 ms
55,596 KB
testcase_04 AC 40 ms
55,596 KB
testcase_05 AC 39 ms
55,596 KB
testcase_06 AC 197 ms
126,960 KB
testcase_07 AC 191 ms
127,344 KB
testcase_08 AC 184 ms
127,344 KB
testcase_09 AC 197 ms
127,344 KB
testcase_10 AC 39 ms
55,596 KB
testcase_11 AC 36 ms
55,596 KB
testcase_12 AC 37 ms
55,596 KB
testcase_13 AC 38 ms
55,596 KB
testcase_14 AC 259 ms
149,232 KB
testcase_15 AC 194 ms
129,776 KB
testcase_16 AC 83 ms
82,892 KB
testcase_17 AC 51 ms
68,732 KB
testcase_18 AC 198 ms
129,776 KB
testcase_19 AC 187 ms
124,556 KB
testcase_20 AC 192 ms
128,340 KB
testcase_21 AC 189 ms
129,776 KB
testcase_22 AC 151 ms
106,980 KB
testcase_23 AC 109 ms
91,368 KB
testcase_24 AC 224 ms
129,776 KB
testcase_25 AC 178 ms
119,488 KB
testcase_26 AC 63 ms
78,292 KB
testcase_27 AC 280 ms
150,128 KB
testcase_28 AC 145 ms
102,652 KB
testcase_29 AC 102 ms
85,848 KB
testcase_30 AC 305 ms
150,128 KB
testcase_31 AC 74 ms
79,060 KB
testcase_32 AC 74 ms
78,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

n,x,y = map(int,input().split())
cus = [list(map(str,input().split())) for i in range(n)]
all = [[0,0] for i in range(n)]
tot = 0 
for i in range(n):
    pi,ci = cus[i]
    pi = int(pi)
    tot += pi
    if ci == "A":
        all[i%(x+y)][0] += pi
    else:
        all[i%(x+y)][1] += pi
    
a = []
for i in range(min(x+y, n)):
    a.append(all[i][0] - all[i][1])

ans = 0
if n >= x+y:
    a.sort()
    for i in range(x):
        ans += a.pop()
    for i in range(y):
        ans -= a.pop()

else:
    aa = []
    bb = []
    for i in range(n):
        pi,ci = cus[i]
        if ci == "A":
            aa.append(int(pi))
        else:
            bb.append(int(pi))
    aa.sort()
    bb.sort()
    for i in range(min(len(aa), x)):
        ans += aa.pop()
    for i in range(min(len(bb), y)):
        ans += bb.pop()
    
    ans -= sum(aa)
    ans -= sum(bb)

    
        


print((ans+tot)//2)
        
0