結果

問題 No.3697 実力を揃える
コンテスト
ユーザー あるふぁ
提出日時 2026-09-13 10:38:42
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 803 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,909 ms
コンパイル使用メモリ 361,792 KB
実行使用メモリ 19,944 KB
最終ジャッジ日時 2026-09-13 10:38:53
合計ジャッジ時間 5,928 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    for (ll& x : A) cin >> x;

    int M = N/2;
    vector<ll> L(A.begin(), A.begin()+M);
    vector<ll> R(A.begin()+M, A.end());
    vector<ll> LS, RS;
    for (int bit = 0; bit < (1<<M); bit++){
        ll ls = 0, rs = 0;
        for (int i = 0; i < M; i++){
            if (bit>>i&1) ls += L[i], rs += R[i];
        }
        LS.push_back(ls);
        RS.push_back(rs);
    }

    sort(LS.begin(), LS.end());
    sort(RS.begin(), RS.end());
    ll S = reduce(A.begin(), A.end());
    ll res = 0;
    for (int x : LS){
        auto it = upper_bound(RS.begin(), RS.end(), S/2-x);
        if (it != RS.begin()) res = max(res, x+*(--it));
    }

    cout << S-2*res << endl;
}
0