結果

問題 No.21 平均の差
ユーザー ioryyyyzioryyyyz
提出日時 2015-07-24 07:06:20
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 799 bytes
コンパイル時間 2,899 ms
コンパイル使用メモリ 149,228 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 22:04:57
合計ジャッジ時間 2,069 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> v(N);
    for(int i=0;i<N;++i)
        cin >> v[i];

    sort(begin(v), end(v));

    vector<int> sums(N);
    sums[0] = v[0];
    for(int i=1;i<N;++i){
        sums[i] = sums[i-1] + v[i];
    }

    double ans = 0;
    for(int i=0;i<N-K;++i){
        double lower_average = (double)sums[i] / (i+1);
        for(int j=i+K-2;j<N-1;++j){
            int numbers = N - j - 1;
            // cout << j << " " << numbers << endl;
            double upper_average = (sums[N-1] - sums[j]) / numbers;
            // cout << lower_average << " " << upper_average << endl;
            ans = max(ans, floor(upper_average - lower_average));
        }
    }
    cout << int(ans) << endl;
    return 0;
}
0