結果

問題 No.609 Noelちゃんと星々
ユーザー pinpin
提出日時 2017-12-09 04:04:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 670 bytes
コンパイル時間 1,064 ms
コンパイル使用メモリ 84,380 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-07 09:08:29
合計ジャッジ時間 2,728 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
5,248 KB
testcase_01 AC 22 ms
5,376 KB
testcase_02 AC 15 ms
5,376 KB
testcase_03 AC 20 ms
5,376 KB
testcase_04 AC 11 ms
5,376 KB
testcase_05 AC 50 ms
5,376 KB
testcase_06 AC 44 ms
5,376 KB
testcase_07 AC 26 ms
5,376 KB
testcase_08 AC 7 ms
5,376 KB
testcase_09 AC 17 ms
5,376 KB
testcase_10 AC 32 ms
5,376 KB
testcase_11 AC 30 ms
5,376 KB
testcase_12 AC 38 ms
5,376 KB
testcase_13 AC 8 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 45 ms
5,376 KB
testcase_16 AC 51 ms
5,376 KB
testcase_17 AC 41 ms
5,376 KB
testcase_18 AC 14 ms
5,376 KB
testcase_19 AC 43 ms
5,376 KB
testcase_20 AC 53 ms
5,376 KB
testcase_21 AC 54 ms
5,376 KB
testcase_22 AC 53 ms
5,376 KB
testcase_23 AC 53 ms
5,376 KB
testcase_24 AC 53 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;

const ll INF = 1000000005;
ll n;
ll y[100005];
ll sum[100005];

int main(void){
    cin >> n;
 
    for (int i = 0; i < n; i++) cin >> y[i];
    sort(y, y + n);
    for (int i = 0; i < n; i++){
        sum[i] = y[i];
        if (i != 0) sum[i] += sum[i - 1];
    }

    ll ans = 1000000000000000;
    for (int i = 0; i < n; i++){
        ans = min(ans, y[i] * (2 * i + 2 - n) - 2 * sum[i] + sum[n - 1]);
    }

    cout << ans << endl;

}
0