結果

問題 No.2623 Room Allocation
ユーザー hals
提出日時 2024-02-29 17:30:44
言語 Julia
(2.11.2)
結果
AC  
実行時間 1,289 ms / 2,000 ms
コード長 1,521 bytes
コンパイル時間 73 ms
コンパイル使用メモリ 6,692 KB
実行使用メモリ 308,080 KB
最終ジャッジ日時 2024-10-01 17:45:44
合計ジャッジ時間 29,398 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

function main()
    n, x, y = int(inputs())
    wantA_by_group = zeros(Int, x + y)
    wantB_by_group = zeros(Int, x + y)
    for i = 1:n
        p, c = inputs()
        p = int(p)
        if c == "A"
            wantA_by_group[(i-1)%(x+y)+1] += p
        else
            wantB_by_group[(i-1)%(x+y)+1] += p
        end
    end
    ans = 0
    tmp = []
    for i = 1:x+y
        push!(tmp, (abs(wantA_by_group[i] - wantB_by_group[i]), i))
    end
    sort!(tmp, by=x -> x[1], rev=true)
    ischecked = falses(x + y)
    for i = 1:x+y
        val, group = tmp[i]
        if ischecked[group]
            continue
        end
        ischecked[group] = true
        if wantA_by_group[group] > wantB_by_group[group]
            if x > 0
                ans += wantA_by_group[group]
                x -= 1
            else
                ans += wantB_by_group[group]
                y -= 1
            end
        else
            if y > 0
                ans += wantB_by_group[group]
                y -= 1
            else
                ans += wantA_by_group[group]
                x -= 1
            end
        end
    end
    println(ans)
end
# --------input func----------
input() = readline()
inputs() = split(readline())
int(s::AbstractChar) = parse(Int, s)
int(s::AbstractString) = parse(Int, s)
int(v::AbstractArray) = map(x -> parse(Int, x), v)
debug(x...) = println(stderr, x...)
isfile("myinput.txt") && (mystdin = open("myinput.txt", "r"); redirect_stdin(mystdin))
main()
@isdefined(mystdin) && close(mystdin)
0