結果

問題 No.21 平均の差
ユーザー kshiva1126kshiva1126
提出日時 2019-03-30 18:00:29
言語 Go
(1.21.3)
結果
WA  
実行時間 -
コード長 729 bytes
コンパイル時間 12,489 ms
コンパイル使用メモリ 202,516 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-09 22:39:34
合計ジャッジ時間 12,027 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main
import (
    "fmt"
    "sort"
)
func main(){
    var n, g int
    fmt.Scan(&n)
    fmt.Scan(&g)
    t := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&t[i])
    }
    sort.Ints(t)
    var sp int
    sp = n / g
    var max, min, cnt, total, res float64
    for k, v := range t {
        total += float64(v)
        cnt += 1
        if cnt == float64(sp) || k + 1 == len(t) {
            res = total / cnt
            if max < res {
                if min == 0 {
                    min = max
                }
                max = res
            } else if min > res {
                min = res
            }
            total = 0
            cnt = 0
        }
    }
    fmt.Println(int(max - min))
}
0