結果

問題 No.21 平均の差
ユーザー nayutanayuta
提出日時 2019-12-26 05:11:06
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,010 ms / 5,000 ms
コード長 1,238 bytes
コンパイル時間 937 ms
コンパイル使用メモリ 80,812 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-02 03:17:22
合計ジャッジ時間 2,631 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <numeric> 

using namespace std;

int n, k, ans;
vector<int> a;

void rec(vector<int> &num){

    for(int i = 1; i < n; i++){
        num.push_back(i);
        if(num.size() < k){
            rec(num);
        }else{
            if(accumulate(num.begin(), num.end(), 0) == n){
                vector<double> t(k, 0);
                int id = 0;
                for(int j = 0; j < k; j++){
                    for(int p = 0; p < num[j]; p++){
                        t[j] += a[id];
                        id++;
                    }
                    int sz = num[j];
                    t[j] = t[j] / (double)sz;
                }
                double mx = *max_element(t.begin(), t.end());
                double mn = *min_element(t.begin(), t.end());
                double diff = mx - mn;
                int res = diff + 0.9;
                ans = max(ans, res);
            }
        }
        num.pop_back();
    }
}

int main(void){
    cin >> n >> k;
    a.assign(n, 0);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    vector<int> num;
    rec(num);
    cout << ans << endl;

    return 0;
}
0