結果
問題 | No.21 平均の差 |
ユーザー |
|
提出日時 | 2024-08-22 09:57:41 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 827 bytes |
コンパイル時間 | 7,950 ms |
コンパイル使用メモリ | 215,408 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-08-22 09:57:54 |
合計ジャッジ時間 | 5,452 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
module main;import std;// 集合の分割を列挙するT[][][] partition(T)(T[] arr, int k){T[][][] result;void backtrack(int start, int k, T[][] currentPartition){if (k == 1) {result ~= currentPartition ~ [arr[start .. $]];return;}foreach (i; start .. arr.length.to!int - k + 1)backtrack(i + 1, k - 1, currentPartition ~ [arr[start .. i + 1]]);}backtrack(0, k, []);return result;}void main(){// 入力auto N = readln.chomp.to!int;auto K = readln.chomp.to!int;double[] num;foreach (_; 0 .. N) {num ~= readln.chomp.to!double;}// 答えの計算double max = -1e10, min = 1e10;foreach (p; partition(num, K)) {foreach (e; p) {double m = e.mean;if (max < m)max = m;if (min > m)min = m;}}// 答えの出力writeln(ceil(max - min));}