Submission #2904720


Source Code Expand

Copy
lines = $stdin.read
array = lines.split("\n")

# https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q1155016236
# nが偶数のときはr=n/2
# nが奇数のときはr=(n-1)/2,(n+1)/2
# で最大値をとることになります.

N = array[0].to_i
A = array[1].split(" ").map(&:to_i).sort.reverse

n = A.max
A.delete(n)

max_r_idx = A.map.with_index{|e,idx| [(n/2-e).abs,idx]}.min_by{|arr| arr.first}.last
max_r     = A[max_r_idx]

puts "#{n} #{max_r}"

Submission Info

Submission Time
Task D - Binomial Coefficients
User hiroyuking
Language Ruby (2.3.3)
Score 400
Code Size 478 Byte
Status
Exec Time 108 ms
Memory 14420 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample1.txt, sample2.txt
All 400 / 400 even0.txt, even1.txt, float.txt, odd0.txt, odd1.txt, rnd_0.txt, rnd_1.txt, rnd_2.txt, rnd_3.txt, rnd_4.txt, rnd_5.txt, rnd_6.txt, rnd_7.txt, rnd_8.txt, rnd_9.txt, sample1.txt, sample2.txt
Case Name Status Exec Time Memory
even0.txt 106 ms 14024 KB
even1.txt 106 ms 14024 KB
float.txt 108 ms 14408 KB
odd0.txt 106 ms 14024 KB
odd1.txt 106 ms 14024 KB
rnd_0.txt 99 ms 13872 KB
rnd_1.txt 87 ms 11908 KB
rnd_2.txt 96 ms 13136 KB
rnd_3.txt 89 ms 12012 KB
rnd_4.txt 78 ms 10612 KB
rnd_5.txt 107 ms 14420 KB
rnd_6.txt 86 ms 11688 KB
rnd_7.txt 83 ms 11376 KB
rnd_8.txt 96 ms 12904 KB
rnd_9.txt 94 ms 12696 KB
sample1.txt 7 ms 1788 KB
sample2.txt 7 ms 1788 KB