結果

問題 No.609 Noelちゃんと星々
ユーザー rnazmornazmo
提出日時 2019-12-07 20:01:44
言語 Go
(1.22.1)
結果
AC  
実行時間 1,121 ms / 2,000 ms
コード長 376 bytes
コンパイル時間 10,920 ms
コンパイル使用メモリ 212,572 KB
実行使用メモリ 8,092 KB
最終ジャッジ日時 2023-08-27 00:56:23
合計ジャッジ時間 31,191 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 840 ms
7,940 KB
testcase_01 AC 426 ms
5,684 KB
testcase_02 AC 291 ms
5,656 KB
testcase_03 AC 396 ms
5,680 KB
testcase_04 AC 193 ms
4,380 KB
testcase_05 AC 1,047 ms
7,944 KB
testcase_06 AC 902 ms
7,944 KB
testcase_07 AC 530 ms
5,712 KB
testcase_08 AC 110 ms
4,384 KB
testcase_09 AC 338 ms
5,672 KB
testcase_10 AC 654 ms
7,940 KB
testcase_11 AC 614 ms
7,944 KB
testcase_12 AC 775 ms
7,944 KB
testcase_13 AC 143 ms
4,380 KB
testcase_14 AC 59 ms
4,384 KB
testcase_15 AC 931 ms
7,948 KB
testcase_16 AC 1,080 ms
7,984 KB
testcase_17 AC 851 ms
7,940 KB
testcase_18 AC 288 ms
5,656 KB
testcase_19 AC 893 ms
7,948 KB
testcase_20 AC 1,108 ms
8,092 KB
testcase_21 AC 1,106 ms
8,092 KB
testcase_22 AC 1,116 ms
8,088 KB
testcase_23 AC 1,117 ms
8,092 KB
testcase_24 AC 1,121 ms
8,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://yukicoder.me/problems/no/609

package main

import (
	"fmt"
	"sort"
)

func diff(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func main() {
	var n int
	fmt.Scan(&n)
	ys := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&ys[i])
	}

	sort.Ints(ys)
	med := ys[n/2]

	sum := 0
	for _, y := range ys {
		sum += diff(med, y)
	}
	fmt.Println(sum)
}
0