結果

問題 No.1007 コイン集め
ユーザー rogi52
提出日時 2022-10-05 00:04:34
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 14 ms / 1,500 ms
コード長 729 bytes
コンパイル時間 2,181 ms
コンパイル使用メモリ 194,688 KB
最終ジャッジ日時 2025-02-07 21:41:18
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N,K; cin >> N >> K; K--;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    if(A[K] == 0) {
        cout << 0 << endl;
    } else {
        ll sumL = 0, sumR = 0;
        for(int i = K - 1; i >= 0; i--) {
            sumL += A[i];
            if(A[i] <= 1) break;
        }
        for(int i = K + 1; i < N; i++) {
            sumR += A[i];
            if(A[i] <= 1) break;
        }

        if(A[K] == 1) {
            cout << max(sumL, sumR) + A[K] << endl;
        } else {
            cout << sumL + sumR + A[K] << endl;
        }
    }
}
0