結果

問題 No.21 平均の差
ユーザー commycommy
提出日時 2017-10-09 16:53:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,374 ms / 5,000 ms
コード長 1,049 bytes
コンパイル時間 893 ms
コンパイル使用メモリ 84,304 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 14:22:12
合計ジャッジ時間 3,720 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)

using namespace std;

typedef long long int lli;

int main() {
    int N;
    int K;
    cin >> N >> K;
    vector<int> n(N);
    REP (i, 0, N) cin >> n[i];
    vector<int> dex(N, 0);
    REP (i, 0, K) dex[N - i - 1] = 1;
    int ans = 0;
    sort(n.begin(), n.end());
    do {
        do {
            int cnt = 0;
            int index = 0;
            vector<double> total(K, 0.0);
            REP (i, 0, N) {
                total[index] += n[i];
                cnt++;
                if (dex[i]) {
                    total[index] /= cnt;
                    cnt = 0;
                    index++;
                }
            }
            sort(total.begin(), total.end());
            ans = max(ans, (int)ceil(total[total.size() - 1] - total[0]));
        } while (next_permutation(dex.begin(), dex.end() - 1));
    } while (next_permutation(n.begin(), n.end()));
    cout << ans << endl;
    return 0;
}
0