結果
| 問題 | 
                            No.1150 シュークリームゲーム(Easy)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             poohbear
                         | 
                    
| 提出日時 | 2020-08-07 21:55:19 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 55 ms / 2,000 ms | 
| コード長 | 2,071 bytes | 
| コンパイル時間 | 2,149 ms | 
| コンパイル使用メモリ | 196,428 KB | 
| 最終ジャッジ日時 | 2025-01-12 16:46:17 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 43 | 
ソースコード
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
//入力
ll n;
ll s,t;
vector<ll>a;
int main(){
    cin >> n;
    cin >> s >> t;
    s--;t--;
    a.resize(2*n);
    rep(i,n)cin>>a[i];
    rep(i,n)a[i+n]=a[i];
    ll x = 0;
    ll y = 0;
    if(s<t){
        vector<ll>wait;
        ll ns = s+n;
        int i=0;
        while((s+i)<=(t-i)){
            if(s+i==t-i){
                wait.push_back(a[s+i]);
                break;
            }
            x += a[s+i];
            y += a[t-i];
            i++;
        }
        i=1;
        while((t+i)<=(ns-i)){
            if((t+i)==(ns-i)){
                wait.push_back(a[t+i]);
                break;
            }
            x += a[ns-i];
            y += a[t+i];
            i++;
        }
        if(wait.size()==1){
            x += wait[0];
        }
        if(wait.size()>=2){
            x += max(wait[0],wait[1]);
            y += min(wait[0],wait[1]);
        }
        cout << x-y << endl;
    }
    else{
        vector<ll>wait;
        ll nt = t+n;
        int i=0;
        while((t+i)<=(s-i)){
            if(t+i==s-i){
                wait.push_back(a[t+i]);
                break;
            }
            y += a[t+i];
            x += a[s-i];
            i++;
        }
        i=1;
        while((s+i)<=(nt-i)){
            if((s+i)==(nt-i)){
                wait.push_back(a[s+i]);
                break;
            }
            y += a[nt-i];
            x += a[s+i];
            i++;
        }
        if(wait.size()==1){
            x += wait[0];
        }
        if(wait.size()>=2){
            x += max(wait[0],wait[1]);
            y += min(wait[0],wait[1]);
        }
        cout << x-y << endl;
    }
    return 0;
    
}
            
            
            
        
            
poohbear