結果

問題 No.972 選び方のスコア
ユーザー koi_kotyakoi_kotya
提出日時 2020-01-17 21:55:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 984 bytes
コンパイル時間 1,631 ms
コンパイル使用メモリ 170,104 KB
実行使用メモリ 6,444 KB
最終ジャッジ日時 2023-09-08 02:41:31
合計ジャッジ時間 5,602 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
6,232 KB
testcase_01 AC 94 ms
6,172 KB
testcase_02 AC 90 ms
5,932 KB
testcase_03 AC 43 ms
4,764 KB
testcase_04 AC 86 ms
6,444 KB
testcase_05 AC 86 ms
6,192 KB
testcase_06 AC 86 ms
6,440 KB
testcase_07 AC 71 ms
5,500 KB
testcase_08 AC 76 ms
6,348 KB
testcase_09 AC 73 ms
5,844 KB
testcase_10 AC 76 ms
6,288 KB
testcase_11 AC 81 ms
6,168 KB
testcase_12 AC 82 ms
6,168 KB
testcase_13 AC 81 ms
6,120 KB
testcase_14 AC 82 ms
6,172 KB
testcase_15 AC 82 ms
6,120 KB
testcase_16 AC 83 ms
6,232 KB
testcase_17 AC 83 ms
6,236 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0;i < n;++i) cin >> a[i];
    sort(a.begin(),a.end());
    vector<ll> sums(n+1,0);
    for (int i = 0;i < n;++i) sums[i+1] = sums[i]+a[i];
    ll ans = 0;
    for (int i = 3;i < n;i += 2) {
        int j = (i+1)/2,k = i-j;
        ans = max(ans,sums[j]+sums[n]-sums[n-k]-a[j-1]*i);
    }
    for (int i = 4;i < n;i += 2) {
        int j = i/2+2,k = i-j;
        ans = max(ans,sums[j]+sums[n]-sums[n-k]-(a[j-1]+a[j-2])*i/2);
    }
    cout << ans << endl;
}
0