結果
| 問題 |
No.1251 絶対に間違ってはいけない最小化問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-05-24 09:02:58 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 416 ms / 2,000 ms |
| コード長 | 639 bytes |
| コンパイル時間 | 582 ms |
| コンパイル使用メモリ | 5,248 KB |
| 実行使用メモリ | 30,208 KB |
| 最終ジャッジ日時 | 2024-10-12 16:01:10 |
| 合計ジャッジ時間 | 21,752 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 |
ソースコード
local n = io.read("*n")
local a = {}
for i = 1, n do
a[i] = {io.read("*n")}
end
for i = 1, n do
a[i][2] = io.read("*n")
end
table.sort(a, function(x, y) return x[1] < y[1] end)
local ret = 0LL
local retpos = a[1][1]
local bias = 0LL
local ang = 0LL
for i = 1, n do
ang = ang - a[i][2]
bias = bias + a[i][2] * a[i][1]
end
do
local x = a[1][1]
ret = ang * x + bias
end
for i = 1, n - 1 do
ang = ang + 2 * a[i][2]
bias = bias - 2 * a[i][2] * a[i][1]
local x = a[i + 1][1]
local z = ang * x + bias
if z < ret then
ret = z
retpos = x
end
end
local str = tostring(ret):gsub("LL", "")
print(retpos .. " " .. str)