結果
問題 | No.609 Noelちゃんと星々 |
ユーザー |
![]() |
提出日時 | 2019-04-10 13:24:41 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 26 ms / 2,000 ms |
コード長 | 696 bytes |
コンパイル時間 | 15,477 ms |
コンパイル使用メモリ | 238,692 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-07 03:38:10 |
合計ジャッジ時間 | 14,798 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 |
ソースコード
package main import ( "bufio" "fmt" "math" "os" "sort" "strconv" ) func main() { var n int _, _ = fmt.Scan(&n) bi := bufio.NewScanner(os.Stdin) bi.Split(bufio.ScanWords) sum := 0 nums := make([]int, n) for i := range nums { bi.Scan() a, _ := strconv.Atoi(bi.Text()) sum += a nums[i] = a } sort.Slice(nums, func(i, j int) bool { return nums[i] < nums[j] }) // fmt.Println(nums) l := nums[int(math.Floor(float64(n)/2))] h := nums[int(math.Ceil(float64(n)/2))] // fmt.Println(l, h) var ld, hd int for _, a := range nums { ld += int(math.Abs(float64(l - a))) hd += int(math.Abs(float64(h - a))) } fmt.Println(int(math.Min(float64(ld), float64(hd)))) }