Submission #2777708

Source Code Expand

Copy
N = gets.to_i
as = gets.split.map(&:to_i)
N.times do |i|
    as[i] -= i+1
end

as.sort!

if N%2==0
    med = (as[N/2-1] + as[N/2])/2
else
    med = as[N/2]
end

ans = 0
N.times do |j|
    ans += (med-as[j]).abs
end
puts ans

Submission Info

Submission Time
Task C - Linear Approximation
User betrue12
Language Ruby (2.3.3)
Score 300
Code Size 243 Byte
Status
Exec Time 161 ms
Memory 17536 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All 300 / 300 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt
Case Name Status Exec Time Memory
sample_01.txt 7 ms 1788 KB
sample_02.txt 7 ms 1788 KB
sample_03.txt 7 ms 1788 KB
sample_04.txt 7 ms 1788 KB
subtask_1_01.txt 7 ms 1788 KB
subtask_1_02.txt 34 ms 4352 KB
subtask_1_03.txt 28 ms 4096 KB
subtask_1_04.txt 71 ms 9088 KB
subtask_1_05.txt 125 ms 15668 KB
subtask_1_06.txt 134 ms 17032 KB
subtask_1_07.txt 161 ms 17508 KB
subtask_1_08.txt 137 ms 17520 KB
subtask_1_09.txt 140 ms 17508 KB
subtask_1_10.txt 139 ms 17536 KB
subtask_1_11.txt 139 ms 17520 KB