結果

問題 No.972 選び方のスコア
ユーザー face4face4
提出日時 2020-01-17 22:54:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 799 bytes
コンパイル時間 780 ms
コンパイル使用メモリ 75,952 KB
実行使用メモリ 6,412 KB
最終ジャッジ日時 2023-09-08 06:15:51
合計ジャッジ時間 5,248 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
6,200 KB
testcase_01 AC 110 ms
6,244 KB
testcase_02 AC 105 ms
5,916 KB
testcase_03 AC 51 ms
4,620 KB
testcase_04 AC 102 ms
6,312 KB
testcase_05 AC 103 ms
6,228 KB
testcase_06 AC 102 ms
6,296 KB
testcase_07 AC 83 ms
5,400 KB
testcase_08 AC 94 ms
6,120 KB
testcase_09 AC 90 ms
5,872 KB
testcase_10 AC 92 ms
6,300 KB
testcase_11 AC 98 ms
6,232 KB
testcase_12 AC 99 ms
6,412 KB
testcase_13 AC 98 ms
6,192 KB
testcase_14 AC 98 ms
6,156 KB
testcase_15 AC 98 ms
6,124 KB
testcase_16 AC 99 ms
6,096 KB
testcase_17 AC 99 ms
6,200 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 98 ms
6,096 KB
testcase_20 AC 98 ms
6,120 KB
testcase_21 AC 98 ms
6,156 KB
testcase_22 AC 98 ms
5,892 KB
testcase_23 AC 97 ms
6,192 KB
testcase_24 AC 97 ms
6,296 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,384 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<ll> v(n+1, 0);
    for(int i = 1; i <= n; i++)  cin >> v[i];
    sort(v.begin(), v.end());
    vector<ll> sum = v;
    for(int i = 1; i <= n; i++) sum[i] += sum[i-1];
    ll ans = 0;
    for(int i = 2; i < n; i++){
        if(v[n]-v[i]+v[i-1]-v[i] < 0)   continue;
        int l = 1, r = min(i-1, n-i)+1;
        while(r-l > 1){
            int mid = (l+r)/2;
            // n-mid-1 になってた(!!)
            if(v[n-mid+1]-v[i]+v[i-mid]-v[i] >= 0)  l = mid;
            else                                    r = mid;
        }
        ans = max(ans, sum[n]-sum[n-l]+sum[i-1]-sum[i-1-l]-2*l*v[i]);
    }
    cout << ans << endl;
    return 0;
}
0