結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー trineutron
提出日時 2020-08-08 07:56:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 937 bytes
コンパイル時間 2,312 ms
コンパイル使用メモリ 200,348 KB
最終ジャッジ日時 2025-01-12 18:46:21
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int n, s, t;
    cin >> n >> s >> t;
    s--; t--;
    vector<int64_t> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    
    auto distance = [n](int k, int l) {
        return min(abs(k - l), n - abs(k - l));
    };
    
    int64_t s_315 = 0, s_8128 = 0;
    vector<int64_t> neutral;
    for (int i = 0; i < n; i++) {
        int d_315 = distance(i, s), d_8128 = distance(i, t);
        if (d_315 < d_8128) {
            s_315 += a.at(i);
        } else if (d_315 > d_8128) {
            s_8128 += a.at(i);
        } else {
            neutral.push_back(a.at(i));
        }
    }
    sort(neutral.rbegin(), neutral.rend());
    
    for (int i = 0; i < neutral.size(); i++) {
        if (i == 0) {
            s_315 += neutral.at(i);
        } else {
            s_8128 += neutral.at(i);
        }
    }
    
    cout << s_315 - s_8128 << endl;
}
0