Submission #2082624
Source Code Expand
n = gets.to_i
xs = gets.split(" ").map(&:to_i) # 売却価格
cs = gets.split(" ").map(&:to_i) # 販売価格
vs = gets.split(" ").map(&:to_i) # 価値
selling = [true] * n
have_from = 0
money = 0
# 販売されているもののうち, 価値に比べて販売価格が最も下回っているものの番号を返す
def n_max_moukaru(cs, vs, selling)
num = -1
maxval = 0
# maxval = -9999999999999
[*0..(cs.size-1)].each{|i|
if (vs[i] - cs[i]) > maxval and selling[i] then
maxval = vs[i] - cs[i]
num = i
end
}
return num
end
# money で購入可能なもののうち, 価値に比べて販売価格が最も下回っているものの番号を返す.
# もし何も買えない場合, money で購入可能でないものについても調べて返す
def n_max_sonsuru(cs, vs, selling, money)
num = -1
maxval = -9999999999999
[*0..(cs.size-1)].each{|i|
if (vs[i] - cs[i]) > maxval and selling[i] and money >= cs[i] then
maxval = vs[i] - cs[i]
num = i
end
}
num = n_max_moukaru(cs, vs, selling) if num == -1
return num
end
total_value = 0
[*0..(n-1)].each{|i|
itmp = n_max_moukaru(cs, vs, selling)
if itmp >= 0 and money >= cs[itmp] then
# 購入
total_value += vs[itmp]
money -= cs[itmp]
else
# 売却
money += xs[have_from]
have_from += 1
end
itmp = n_max_sonsuru(cs, vs, selling, money)
selling[itmp] = false
}
puts total_value
Submission Info
| Submission Time | |
|---|---|
| Task | C - 駆引取引 |
| User | stsnoda |
| Language | Ruby (2.3.3) |
| Score | 0 |
| Code Size | 1500 Byte |
| Status | WA |
| Exec Time | 7 ms |
| Memory | 1788 KiB |
Judge Result
| Set Name | Sample | All | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 500 | ||||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 00_example_04.txt |
| All | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 00_example_04.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_example_01.txt | AC | 7 ms | 1788 KiB |
| 00_example_02.txt | AC | 7 ms | 1788 KiB |
| 00_example_03.txt | AC | 7 ms | 1788 KiB |
| 00_example_04.txt | WA | 7 ms | 1788 KiB |
| 01.txt | WA | 7 ms | 1788 KiB |
| 02.txt | WA | 7 ms | 1788 KiB |
| 03.txt | WA | 7 ms | 1788 KiB |
| 04.txt | WA | 7 ms | 1788 KiB |
| 05.txt | WA | 7 ms | 1788 KiB |
| 06.txt | WA | 7 ms | 1788 KiB |
| 07.txt | WA | 7 ms | 1788 KiB |
| 08.txt | WA | 7 ms | 1788 KiB |
| 09.txt | WA | 7 ms | 1788 KiB |
| 10.txt | WA | 7 ms | 1788 KiB |
| 11.txt | WA | 7 ms | 1788 KiB |
| 12.txt | WA | 7 ms | 1788 KiB |
| 13.txt | WA | 7 ms | 1788 KiB |
| 14.txt | WA | 7 ms | 1788 KiB |
| 15.txt | WA | 7 ms | 1788 KiB |
| 16.txt | WA | 7 ms | 1788 KiB |
| 17.txt | WA | 7 ms | 1788 KiB |
| 18.txt | WA | 7 ms | 1788 KiB |
| 19.txt | WA | 7 ms | 1788 KiB |
| 20.txt | WA | 7 ms | 1788 KiB |
| 21.txt | WA | 7 ms | 1788 KiB |
| 22.txt | WA | 7 ms | 1788 KiB |
| 23.txt | WA | 7 ms | 1788 KiB |
| 24.txt | WA | 7 ms | 1788 KiB |
| 25.txt | WA | 7 ms | 1788 KiB |
| 26.txt | WA | 7 ms | 1788 KiB |
| 27.txt | AC | 7 ms | 1788 KiB |
| 28.txt | WA | 7 ms | 1788 KiB |
| 29.txt | AC | 7 ms | 1788 KiB |
| 30.txt | WA | 7 ms | 1788 KiB |
| 31.txt | WA | 7 ms | 1788 KiB |
| 32.txt | WA | 7 ms | 1788 KiB |
| 33.txt | WA | 7 ms | 1788 KiB |
| 34.txt | WA | 7 ms | 1788 KiB |
| 35.txt | WA | 7 ms | 1788 KiB |
| 36.txt | WA | 7 ms | 1788 KiB |
| 37.txt | WA | 7 ms | 1788 KiB |
| 38.txt | WA | 7 ms | 1788 KiB |
| 39.txt | WA | 7 ms | 1788 KiB |