結果

問題 No.3252 Constrained Moving
ユーザー Tatsu_mr
提出日時 2025-09-05 22:41:25
言語 Ruby
(3.4.1)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 425 bytes
コンパイル時間 459 ms
コンパイル使用メモリ 8,064 KB
実行使用メモリ 26,880 KB
最終ジャッジ日時 2025-09-05 22:41:49
合計ジャッジ時間 8,430 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:22: warning: ambiguous first argument; put parentheses or a space even after `-` operator
Syntax OK

ソースコード

diff #

n, s, t, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
s -= 1
t -= 1

if a[s] + a[t] <= k then
    puts 1
else
    # a[s] -> min(A) -> a[t]
    mn = 2_000_000_000
    (0..n - 1).each do |i|
        if i == s or i == t then
            next
        end
        if mn > a[i] then
            mn = a[i]
        end
    end
    if a[s] + mn <= k and mn + a[t] <= k then
        puts 2
    else
        puts -1
    end
end
0