結果

問題 No.2835 Take and Flip
ユーザー かちわけかちわけ
提出日時 2024-08-09 21:48:19
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 405 bytes
コンパイル時間 1,802 ms
コンパイル使用メモリ 178,808 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-08-09 21:48:24
合計ジャッジ時間 4,254 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0 ; (i)<(int)(n) ; (i)++)

int main(void){
    int n;
    cin >> n;
    deque<int> a(n);
    REP(i, n) cin >> a.at(i);
    sort(a.begin(), a.end());
    
    long long ans = 0;
    REP(i, (n+1)/2){
        ans += a.at(n-1-i);
        if(n%2 != 0 && i == n/2) continue;
        else ans += a.at(i);
    }
    cout << ans << endl;
}
0